method

add_exclusion_constraint

Importance_2
v8.0.0 - Show latest stable - 0 notes - Class: 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).

Show source
Register or log in to add new notes.