I’m not sure when this was added to Ecto, but at least in 2.1.6 there’s no need for raw SQL anymore. drop/1
now supports constraints (drop_if_exists/1
doesn’t though):
def up do
drop constraint(:videos, "videos_user_id_fkey")
alter table(:videos) do
modify :user_id, references(:users, on_delete: :delete_all)
end
end
def down do
drop constraint(:videos, "videos_user_id_fkey")
alter table(:videos) do
modify :user_id, references(:users, on_delete: :nothing)
end
end