forked from AkkomaGang/akkoma
parent
5f7d47dcb7
commit
8cf183cb42
2 changed files with 50 additions and 2 deletions
50
priv/repo/migrations/20240210000000_drop_chat_tables.exs
Normal file
50
priv/repo/migrations/20240210000000_drop_chat_tables.exs
Normal file
|
@ -0,0 +1,50 @@
|
|||
defmodule Pleroma.Repo.Migrations.DropChatTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
# Automatically drops associated indices and constraints
|
||||
drop table(:chat_message_references)
|
||||
drop table(:chats)
|
||||
end
|
||||
|
||||
def down do
|
||||
# Ecto's default primary key is bigserial, thus configure manually
|
||||
create table(:chats, primary_key: false) do
|
||||
add(:id, :uuid, primary_key: true, autogenerated: true)
|
||||
|
||||
add(
|
||||
:user_id,
|
||||
references(:users, type: :uuid, on_delete: :delete_all)
|
||||
# yes, this was nullable
|
||||
)
|
||||
|
||||
add(
|
||||
:recipient,
|
||||
references(:users, column: :ap_id, type: :string, on_delete: :delete_all)
|
||||
# yes, this was nullable
|
||||
)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create(index(:chats, [:user_id, :recipient], unique: true))
|
||||
|
||||
create table(:chat_message_references, primary_key: false) do
|
||||
add(:id, :uuid, primary_key: true, autogenerated: true)
|
||||
add(:chat_id, references(:chats, type: :uuid, on_delete: :delete_all), null: false)
|
||||
add(:object_id, references(:objects, on_delete: :delete_all), null: false)
|
||||
add(:unread, :boolean, default: true, null: false)
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create(index(:chat_message_references, [:chat_id, "id desc"]))
|
||||
create(unique_index(:chat_message_references, [:object_id, :chat_id]))
|
||||
|
||||
create(
|
||||
index(:chat_message_references, [:chat_id],
|
||||
where: "unread = true",
|
||||
name: "unread_messages_count_index"
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
|
@ -371,8 +371,6 @@ test "We don't have unexpected tables which may contain objects that are referen
|
|||
["apps"],
|
||||
["backups"],
|
||||
["bookmarks"],
|
||||
["chat_message_references"],
|
||||
["chats"],
|
||||
["config"],
|
||||
["conversation_participation_recipient_ships"],
|
||||
["conversation_participations"],
|
||||
|
|
Loading…
Reference in a new issue