logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

20200831142509_chat_constraints.exs (707B)


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