summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-08-31 16:48:17 +0200
committerlain <lain@soykaf.club>2020-08-31 16:48:17 +0200
commit0b621a834acf751332f4d202bd50d4ff3e789176 (patch)
tree89fc93191f49d92050102935bf8aad1a7aacfa90 /priv
parent0417b2f649172ea300c124159aa86b964e404a0c (diff)
Chats: Add cascading delete on both referenced users.
Also remove the now-superfluous join in the chat controller, which was only used to filter out these cases.
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200831142509_chat_constraints.exs22
1 files changed, 22 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200831142509_chat_constraints.exs b/priv/repo/migrations/20200831142509_chat_constraints.exs
new file mode 100644
index 000000000..868a40a45
--- /dev/null
+++ b/priv/repo/migrations/20200831142509_chat_constraints.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.Repo.Migrations.ChatConstraints do
+ use Ecto.Migration
+
+ def change do
+ remove_orphans = """
+ delete from chats where not exists(select id from users where ap_id = chats.recipient);
+ """
+
+ execute(remove_orphans)
+
+ drop(constraint(:chats, "chats_user_id_fkey"))
+
+ alter table(:chats) do
+ modify(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+
+ modify(
+ :recipient,
+ references(:users, column: :ap_id, type: :string, on_delete: :delete_all)
+ )
+ end
+ end
+end