From 99caae332ceee2cf061744ab7f6ab324579f83b7 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 23 Oct 2019 16:02:01 +0200 Subject: [PATCH] Make actors deletion cascade to followers Signed-off-by: Thomas Citharel --- ...805_delete_actors_cascade_to_followers.exs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 priv/repo/migrations/20191023133805_delete_actors_cascade_to_followers.exs diff --git a/priv/repo/migrations/20191023133805_delete_actors_cascade_to_followers.exs b/priv/repo/migrations/20191023133805_delete_actors_cascade_to_followers.exs new file mode 100644 index 000000000..d5b4d66da --- /dev/null +++ b/priv/repo/migrations/20191023133805_delete_actors_cascade_to_followers.exs @@ -0,0 +1,23 @@ +defmodule Mobilizon.Storage.Repo.Migrations.DeleteActorsCascadeToFollowers do + use Ecto.Migration + + def up do + drop(constraint(:followers, "followers_actor_id_fkey")) + drop(constraint(:followers, "followers_target_actor_id_fkey")) + + alter table(:followers) do + modify(:actor_id, references(:actors, on_delete: :delete_all)) + modify(:target_actor_id, references(:actors, on_delete: :delete_all)) + end + end + + def down do + drop(constraint(:followers, "followers_actor_id_fkey")) + drop(constraint(:followers, "followers_target_actor_id_fkey")) + + alter table(:followers) do + modify(:actor_id, references(:actors, on_delete: :nothing)) + modify(:target_actor_id, references(:actors, on_delete: :nothing)) + end + end +end