Merge branch 'stable' into stable-sync/2.1.1
[akkoma] / priv / repo / migrations / 20200831142509_chat_constraints.exs
1 defmodule Pleroma.Repo.Migrations.ChatConstraints do
2 use Ecto.Migration
3
4 def change do
5 remove_orphans = """
6 delete from chats where not exists(select id from users where ap_id = chats.recipient);
7 """
8
9 execute(remove_orphans)
10
11 drop(constraint(:chats, "chats_user_id_fkey"))
12
13 alter table(:chats) do
14 modify(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
15
16 modify(
17 :recipient,
18 references(:users, column: :ap_id, type: :string, on_delete: :delete_all)
19 )
20 end
21 end
22 end