Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
548B

  1. defmodule Pleroma.Repo.Migrations.ChatConstraints do
  2. use Ecto.Migration
  3. def change do
  4. remove_orphans = """
  5. delete from chats where not exists(select id from users where ap_id = chats.recipient);
  6. """
  7. execute(remove_orphans)
  8. drop(constraint(:chats, "chats_user_id_fkey"))
  9. alter table(:chats) do
  10. modify(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
  11. modify(
  12. :recipient,
  13. references(:users, column: :ap_id, type: :string, on_delete: :delete_all)
  14. )
  15. end
  16. end
  17. end