First
[anni] / priv / repo / migrations / 20190408123347_create_conversations.exs
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
5 defmodule Pleroma.Repo.Migrations.CreateConversations do
6   use Ecto.Migration
7
8   def change do
9     create_if_not_exists table(:conversations) do
10       add(:ap_id, :string, null: false)
11       timestamps()
12     end
13
14     create_if_not_exists table(:conversation_participations) do
15       add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
16       add(:conversation_id, references(:conversations, on_delete: :delete_all))
17       add(:read, :boolean, default: false)
18
19       timestamps()
20     end
21
22     create_if_not_exists(index(:conversation_participations, [:conversation_id]))
23     create_if_not_exists(unique_index(:conversation_participations, [:user_id, :conversation_id]))
24     create_if_not_exists(unique_index(:conversations, [:ap_id]))
25   end
26 end