Add A Check Constraint To A Table
class EnsurePageCountIsPositive < ActiveRecord::Migration[5.2]
def up
execute <<-SQL
alter table books
add constraint ensure_page_count_is_positive
check (page_count > 0);
SQL
end
def down
execute <<-SQL
alter table books
drop constraint ensure_page_count_is_positive;
SQL
endLast updated