migration: add on_delete: :delete_all to hashtags object_id fk
authorfaried nawaz <faried@gmail.com>
Tue, 20 Apr 2021 21:37:03 +0000 (02:37 +0500)
committerfaried nawaz <faried@gmail.com>
Fri, 7 May 2021 21:00:34 +0000 (02:00 +0500)
priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs [new file with mode: 0644]

diff --git a/priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs b/priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs
new file mode 100644 (file)
index 0000000..f4ebf53
--- /dev/null
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.DeleteHashtagsObjectsCascade do
+  use Ecto.Migration
+
+  def up do
+    execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")
+
+    alter table(:hashtags_objects) do
+      modify(:object_id, references(:objects, on_delete: :delete_all))
+    end
+  end
+
+  def down do
+    execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")
+
+    alter table(:hashtags_objects) do
+      modify(:object_id, references(:objects, on_delete: :nothing))
+    end
+  end
+end