3 ms·
When I type: def up execute <<-SQL alter table users add constraint active_users_must_have_email check active = false OR email is n
by phamilton 5y ago
When I type:
def up
execute <<-SQL
alter table users
add constraint active_users_must_have_email
check active = false OR email is not null
NOT VALID
SQL
i.e. I am adding a check constraint but making it NOT VALID so it won't lock the table while scanning
If I continue and write
execute <<-SQL
a
then it completes it with
alter table users
And then the next line I type
v
and it completes it with
validate constraint active_users_must_have_email
SQL
I then type
end
and it suggests:
def down
execute <<-SQL
ALTER TABLE users
DROP CONSTRAINT IF EXISTS constraint active_users_must_have_email;
SQL
end
Which is exactly what I needed.
What impresses me is that a) it recognized that a NOT VALID index needs to be VALIDATEd and b) it figured out what the down migration was.