method
add_exclusion_constraint
v8.1.1 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements
add_exclusion_constraint(table_name, expression, **options)public
Adds a new exclusion constraint to the table. expression is a String representation of a list of exclusion elements and operators.
add_exclusion_constraint :products, "price WITH =, availability_range WITH &&", using: :gist, name: "price_check"
generates:
ALTER TABLE "products" ADD CONSTRAINT price_check EXCLUDE USING gist (price WITH =, availability_range WITH &&)
The options hash can include the following keys:
- :name
-
The constraint name. Defaults to excl_rails_<identifier>.
- :deferrable
-
Specify whether or not the exclusion constraint should be deferrable. Valid values are false or :immediate or :deferred to specify the default behavior. Defaults to false.
- :using
-
Specify which index method to use when creating this exclusion constraint (e.g. :btree, :gist etc).
- :where
-
Specify an exclusion constraint on a subset of the table (internally PostgreSQL creates a partial index for this).