1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.ChatConstraints do
10 delete from chats where not exists(select id from users where ap_id = chats.recipient);
13 execute(remove_orphans)
15 drop(constraint(:chats, "chats_user_id_fkey"))
17 alter table(:chats) do
18 modify(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
22 references(:users, column: :ap_id, type: :string, on_delete: :delete_all)