aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200309123730_create_chats.exs16
-rw-r--r--priv/repo/migrations/20200602094828_add_type_to_notifications.exs9
-rw-r--r--priv/repo/migrations/20200602125218_backfill_notification_types.exs10
-rw-r--r--priv/repo/migrations/20200602150528_create_chat_message_reference.exs20
-rw-r--r--priv/repo/migrations/20200603105113_add_unique_index_to_chat_message_references.exs7
-rw-r--r--priv/repo/migrations/20200603120448_remove_unread_from_chats.exs9
-rw-r--r--priv/repo/migrations/20200603122732_add_seen_index_to_chat_message_references.exs12
-rw-r--r--priv/repo/migrations/20200604150318_migrate_seen_to_unread_in_chat_message_references.exs30
-rw-r--r--priv/repo/migrations/20200606105430_change_type_to_enum_for_notifications.exs36
-rw-r--r--priv/repo/migrations/20200607112923_change_chat_id_to_flake.exs23
-rw-r--r--priv/static/schemas/litepub-0.1.jsonld1
11 files changed, 173 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200309123730_create_chats.exs b/priv/repo/migrations/20200309123730_create_chats.exs
new file mode 100644
index 000000000..715d798ea
--- /dev/null
+++ b/priv/repo/migrations/20200309123730_create_chats.exs
@@ -0,0 +1,16 @@
+defmodule Pleroma.Repo.Migrations.CreateChats do
+ use Ecto.Migration
+
+ def change do
+ create table(:chats) do
+ add(:user_id, references(:users, type: :uuid))
+ # Recipient is an ActivityPub id, to future-proof for group support.
+ add(:recipient, :string)
+ add(:unread, :integer, default: 0)
+ timestamps()
+ end
+
+ # There's only one chat between a user and a recipient.
+ create(index(:chats, [:user_id, :recipient], unique: true))
+ end
+end
diff --git a/priv/repo/migrations/20200602094828_add_type_to_notifications.exs b/priv/repo/migrations/20200602094828_add_type_to_notifications.exs
new file mode 100644
index 000000000..19c733628
--- /dev/null
+++ b/priv/repo/migrations/20200602094828_add_type_to_notifications.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddTypeToNotifications do
+ use Ecto.Migration
+
+ def change do
+ alter table(:notifications) do
+ add(:type, :string)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200602125218_backfill_notification_types.exs b/priv/repo/migrations/20200602125218_backfill_notification_types.exs
new file mode 100644
index 000000000..996d721ee
--- /dev/null
+++ b/priv/repo/migrations/20200602125218_backfill_notification_types.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.BackfillNotificationTypes do
+ use Ecto.Migration
+
+ def up do
+ Pleroma.MigrationHelper.NotificationBackfill.fill_in_notification_types()
+ end
+
+ def down do
+ end
+end
diff --git a/priv/repo/migrations/20200602150528_create_chat_message_reference.exs b/priv/repo/migrations/20200602150528_create_chat_message_reference.exs
new file mode 100644
index 000000000..6f9148b7c
--- /dev/null
+++ b/priv/repo/migrations/20200602150528_create_chat_message_reference.exs
@@ -0,0 +1,20 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.CreateChatMessageReference do
+ use Ecto.Migration
+
+ def change do
+ create table(:chat_message_references, primary_key: false) do
+ add(:id, :uuid, primary_key: true)
+ add(:chat_id, references(:chats, on_delete: :delete_all), null: false)
+ add(:object_id, references(:objects, on_delete: :delete_all), null: false)
+ add(:seen, :boolean, default: false, null: false)
+
+ timestamps()
+ end
+
+ create(index(:chat_message_references, [:chat_id, "id desc"]))
+ end
+end
diff --git a/priv/repo/migrations/20200603105113_add_unique_index_to_chat_message_references.exs b/priv/repo/migrations/20200603105113_add_unique_index_to_chat_message_references.exs
new file mode 100644
index 000000000..fdf85132e
--- /dev/null
+++ b/priv/repo/migrations/20200603105113_add_unique_index_to_chat_message_references.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddUniqueIndexToChatMessageReferences do
+ use Ecto.Migration
+
+ def change do
+ create(unique_index(:chat_message_references, [:object_id, :chat_id]))
+ end
+end
diff --git a/priv/repo/migrations/20200603120448_remove_unread_from_chats.exs b/priv/repo/migrations/20200603120448_remove_unread_from_chats.exs
new file mode 100644
index 000000000..6322137d5
--- /dev/null
+++ b/priv/repo/migrations/20200603120448_remove_unread_from_chats.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.RemoveUnreadFromChats do
+ use Ecto.Migration
+
+ def change do
+ alter table(:chats) do
+ remove(:unread, :integer, default: 0)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200603122732_add_seen_index_to_chat_message_references.exs b/priv/repo/migrations/20200603122732_add_seen_index_to_chat_message_references.exs
new file mode 100644
index 000000000..a5065d612
--- /dev/null
+++ b/priv/repo/migrations/20200603122732_add_seen_index_to_chat_message_references.exs
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.AddSeenIndexToChatMessageReferences do
+ use Ecto.Migration
+
+ def change do
+ create(
+ index(:chat_message_references, [:chat_id],
+ where: "seen = false",
+ name: "unseen_messages_count_index"
+ )
+ )
+ end
+end
diff --git a/priv/repo/migrations/20200604150318_migrate_seen_to_unread_in_chat_message_references.exs b/priv/repo/migrations/20200604150318_migrate_seen_to_unread_in_chat_message_references.exs
new file mode 100644
index 000000000..fd6bc7bc7
--- /dev/null
+++ b/priv/repo/migrations/20200604150318_migrate_seen_to_unread_in_chat_message_references.exs
@@ -0,0 +1,30 @@
+defmodule Pleroma.Repo.Migrations.MigrateSeenToUnreadInChatMessageReferences do
+ use Ecto.Migration
+
+ def change do
+ drop(
+ index(:chat_message_references, [:chat_id],
+ where: "seen = false",
+ name: "unseen_messages_count_index"
+ )
+ )
+
+ alter table(:chat_message_references) do
+ add(:unread, :boolean, default: true)
+ end
+
+ execute("update chat_message_references set unread = not seen")
+
+ alter table(:chat_message_references) do
+ modify(:unread, :boolean, default: true, null: false)
+ remove(:seen, :boolean, default: false, null: false)
+ end
+
+ create(
+ index(:chat_message_references, [:chat_id],
+ where: "unread = true",
+ name: "unread_messages_count_index"
+ )
+ )
+ end
+end
diff --git a/priv/repo/migrations/20200606105430_change_type_to_enum_for_notifications.exs b/priv/repo/migrations/20200606105430_change_type_to_enum_for_notifications.exs
new file mode 100644
index 000000000..9ea34436b
--- /dev/null
+++ b/priv/repo/migrations/20200606105430_change_type_to_enum_for_notifications.exs
@@ -0,0 +1,36 @@
+defmodule Pleroma.Repo.Migrations.ChangeTypeToEnumForNotifications do
+ use Ecto.Migration
+
+ def up do
+ """
+ create type notification_type as enum (
+ 'follow',
+ 'follow_request',
+ 'mention',
+ 'move',
+ 'pleroma:emoji_reaction',
+ 'pleroma:chat_mention',
+ 'reblog',
+ 'favourite'
+ )
+ """
+ |> execute()
+
+ """
+ alter table notifications
+ alter column type type notification_type using (type::notification_type)
+ """
+ |> execute()
+ end
+
+ def down do
+ alter table(:notifications) do
+ modify(:type, :string)
+ end
+
+ """
+ drop type notification_type
+ """
+ |> execute()
+ end
+end
diff --git a/priv/repo/migrations/20200607112923_change_chat_id_to_flake.exs b/priv/repo/migrations/20200607112923_change_chat_id_to_flake.exs
new file mode 100644
index 000000000..f14e269ca
--- /dev/null
+++ b/priv/repo/migrations/20200607112923_change_chat_id_to_flake.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Repo.Migrations.ChangeChatIdToFlake do
+ use Ecto.Migration
+
+ def up do
+ execute("""
+ alter table chats
+ drop constraint chats_pkey cascade,
+ alter column id drop default,
+ alter column id set data type uuid using cast( lpad( to_hex(id), 32, '0') as uuid),
+ add primary key (id)
+ """)
+
+ execute("""
+ alter table chat_message_references
+ alter column chat_id set data type uuid using cast( lpad( to_hex(chat_id), 32, '0') as uuid),
+ add constraint chat_message_references_chat_id_fkey foreign key (chat_id) references chats(id) on delete cascade
+ """)
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/static/schemas/litepub-0.1.jsonld b/priv/static/schemas/litepub-0.1.jsonld
index 278ad2f96..7cc3fee40 100644
--- a/priv/static/schemas/litepub-0.1.jsonld
+++ b/priv/static/schemas/litepub-0.1.jsonld
@@ -30,6 +30,7 @@
"@type": "@id"
},
"EmojiReact": "litepub:EmojiReact",
+ "ChatMessage": "litepub:ChatMessage",
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"