move to 2.5.5
[anni] / priv / repo / migrations / 20200604150318_migrate_seen_to_unread_in_chat_message_references.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.MigrateSeenToUnreadInChatMessageReferences do
6   use Ecto.Migration
7
8   def change do
9     drop(
10       index(:chat_message_references, [:chat_id],
11         where: "seen = false",
12         name: "unseen_messages_count_index"
13       )
14     )
15
16     alter table(:chat_message_references) do
17       add(:unread, :boolean, default: true)
18     end
19
20     execute("update chat_message_references set unread = not seen")
21
22     alter table(:chat_message_references) do
23       modify(:unread, :boolean, default: true, null: false)
24       remove(:seen, :boolean, default: false, null: false)
25     end
26
27     create(
28       index(:chat_message_references, [:chat_id],
29         where: "unread = true",
30         name: "unread_messages_count_index"
31       )
32     )
33   end
34 end