Method: Sequel::Schema::AlterTableGenerator#add_unique_constraint
- Defined in:
- lib/sequel/database/schema_generator.rb
#add_unique_constraint(columns, opts = OPTS) ⇒ Object
Add a unique constraint to the given column(s)
add_unique_constraint(:name) # ADD UNIQUE (name)
add_unique_constraint(:name, name: :unique_name) # ADD CONSTRAINT unique_name UNIQUE (name)
Supports the same :deferrable option as CreateTableGenerator#column.
PostgreSQL specific options:
- :include
-
Include additional columns in the underlying index, to allow for index-only scans in more cases (PostgreSQL 11+).
- :nulls_not_distinct
-
Use NULLS NOT DISTINCT to setup a constraint where NULL entries are considered distinct (PostgreSQL 15+)
- :using_index
-
Use the USING INDEX clause to specify an existing unique index
- :without_overlaps
-
Use WITHOUT OVERLAPS clause to specify an exclusion constraint on the final column (PostgreSQL 18+, composite unique constraints only).
493 494 495 496 |
# File 'lib/sequel/database/schema_generator.rb', line 493 def add_unique_constraint(columns, opts = OPTS) @operations << {:op => :add_constraint, :type => :unique, :columns => Array(columns)}.merge!(opts) nil end |