Method: Sequel::Schema::CreateTableGenerator#constraint
- Defined in:
- lib/sequel/database/schema_generator.rb
#constraint(name, *args, &block) ⇒ Object
Adds a named CHECK constraint (or unnamed if name is nil), with the given block or args. To provide options for the constraint, pass a hash as the first argument.
constraint(:blah, num: 1..5)
# CONSTRAINT blah CHECK num >= 1 AND num <= 5
constraint({name: :blah, deferrable: true}, num: 1..5)
# CONSTRAINT blah CHECK num >= 1 AND num <= 5 DEFERRABLE INITIALLY DEFERRED
If the first argument is a hash, the following options are supported:
Options:
- :name
-
The name of the CHECK constraint
- :deferrable
-
Whether the CHECK constraint should be marked DEFERRABLE.
PostgreSQL specific options:
- :no_inherit
-
Set NO INHERIT on the constraint, so it will not propogate to child tables.
- :not_enforced
-
Whether the CHECK constraint should be marked NOT ENFORCED.
- :not_valid
-
Whether the CHECK constraint should be marked NOT VALID.
203 204 205 206 207 |
# File 'lib/sequel/database/schema_generator.rb', line 203 def constraint(name, *args, &block) opts = name.is_a?(Hash) ? name : {:name=>name} constraints << opts.merge(:type=>:check, :check=>block || args) nil end |