Search code examples
rubysequel

Complex constraints in Sequel


I have the following constraint in a Sequel migratin:

constraint(:date_is_1_feb_or_1_aug, 'EXTRACT(MONTH FROM date)::INT IN (2,8) AND EXTRACT(DAY FROM date)::INT = 1')

Is there any way to simplify this and use the DSL?


Solution

  • constraint(:date_is_1_feb_or_1_aug,
       Sequel.extract(:month, :date).cast(Integer)=>[2,8],
       Sequel.extract(:day, :date).cast(Integer)=>1)