Fix pictures being deleting cascading to events & posts
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d3573c8a6e
commit
5a062ff11b
31
priv/repo/migrations/20201120161229_fix_picture_deletion.exs
Normal file
31
priv/repo/migrations/20201120161229_fix_picture_deletion.exs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
defmodule Mobilizon.Storage.Repo.Migrations.FixPictureDeletion do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def up do
|
||||||
|
drop_if_exists(constraint(:posts, "posts_picture_id_fkey"))
|
||||||
|
|
||||||
|
alter table(:posts) do
|
||||||
|
modify(:picture_id, references(:pictures, on_delete: :nilify_all))
|
||||||
|
end
|
||||||
|
|
||||||
|
drop_if_exists(constraint(:events, "events_picture_id_fkey"))
|
||||||
|
|
||||||
|
alter table(:events) do
|
||||||
|
modify(:picture_id, references(:pictures, on_delete: :nilify_all))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
drop_if_exists(constraint(:posts, "posts_picture_id_fkey"))
|
||||||
|
|
||||||
|
alter table(:posts) do
|
||||||
|
modify(:picture_id, references(:pictures, on_delete: :delete_all))
|
||||||
|
end
|
||||||
|
|
||||||
|
drop_if_exists(constraint(:events, "events_picture_id_fkey"))
|
||||||
|
|
||||||
|
alter table(:events) do
|
||||||
|
modify(:picture_id, references(:pictures, on_delete: :delete_all))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user