1

Is it possible to define postgres range types in a sequel migration (eg, tsrange)? I found the pg_range extension in the docs, but couldn't find an example migration...

1 Answer 1

1

Sequel makes the Postgres datatypes available as keywords in migrations. Here's one I just did for a bulk discount schedule table, with a constraint to disallow overlapping ranges for the same product group :

create_table(:product_group_bulk_discounts) do
  primary_key :id
  foreign_key :product_group_id, :product_groups, :on_delete=>:cascade
  int4range :quantity
  money :unit_cost_delta, :default=>0, :null=>true
  exclude [[:product_group_id, '='], [:quantity, '&&']]
end

N.B.: This type of exclude constraint requires the btree_gist extension to be loaded on the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.