aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20201128144004_change_user_email_notifications_setting.exs32
-rw-r--r--priv/repo/migrations/20201214160053_add_notified_at_to_notifications.exs15
-rw-r--r--priv/repo/migrations/20201221060622_fill_notifications_notified_at.exs23
-rw-r--r--priv/repo/migrations/20201222052839_add_index_to_notifications.exs7
4 files changed, 77 insertions, 0 deletions
diff --git a/priv/repo/migrations/20201128144004_change_user_email_notifications_setting.exs b/priv/repo/migrations/20201128144004_change_user_email_notifications_setting.exs
new file mode 100644
index 000000000..6ccedfbd0
--- /dev/null
+++ b/priv/repo/migrations/20201128144004_change_user_email_notifications_setting.exs
@@ -0,0 +1,32 @@
+defmodule Pleroma.Repo.Migrations.ChangeUserEmailNotificationsSetting do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def up, do: stream_and_update_users(:up)
+
+ def down, do: stream_and_update_users(:down)
+
+ defp stream_and_update_users(direction) do
+ from(u in Pleroma.User, select: [:id, :email_notifications])
+ |> Pleroma.Repo.stream()
+ |> Stream.each(&update_user_email_notifications_settings(&1, direction))
+ |> Stream.run()
+ end
+
+ defp update_user_email_notifications_settings(user, direction) do
+ email_notifications = change_email_notifications(user.email_notifications, direction)
+
+ user
+ |> Ecto.Changeset.change(email_notifications: email_notifications)
+ |> Pleroma.Repo.update()
+ end
+
+ defp change_email_notifications(email_notifications, :up) do
+ Map.put(email_notifications, "notifications", ["mention", "pleroma:chat_mention"])
+ end
+
+ defp change_email_notifications(email_notifications, :down) do
+ Map.delete(email_notifications, "notifications")
+ end
+end
diff --git a/priv/repo/migrations/20201214160053_add_notified_at_to_notifications.exs b/priv/repo/migrations/20201214160053_add_notified_at_to_notifications.exs
new file mode 100644
index 000000000..4e9255e09
--- /dev/null
+++ b/priv/repo/migrations/20201214160053_add_notified_at_to_notifications.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.AddNotifiedAtToNotifications do
+ use Ecto.Migration
+
+ def up do
+ alter table(:notifications) do
+ add_if_not_exists(:notified_at, :naive_datetime)
+ end
+ end
+
+ def down do
+ alter table(:notifications) do
+ remove_if_exists(:notified_at, :naive_datetime)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20201221060622_fill_notifications_notified_at.exs b/priv/repo/migrations/20201221060622_fill_notifications_notified_at.exs
new file mode 100644
index 000000000..f02899ab7
--- /dev/null
+++ b/priv/repo/migrations/20201221060622_fill_notifications_notified_at.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Repo.Migrations.FillNotificationsNotifiedAt do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ @types ["mention", "pleroma:chat_mention"]
+
+ def up do
+ from(n in "notifications",
+ where: is_nil(n.notified_at),
+ where: n.type in ^@types
+ )
+ |> Pleroma.Repo.update_all(set: [notified_at: NaiveDateTime.utc_now()])
+ end
+
+ def down do
+ from(n in "notifications",
+ where: not is_nil(n.notified_at),
+ where: n.type in ^@types
+ )
+ |> Pleroma.Repo.update_all(set: [notified_at: nil])
+ end
+end
diff --git a/priv/repo/migrations/20201222052839_add_index_to_notifications.exs b/priv/repo/migrations/20201222052839_add_index_to_notifications.exs
new file mode 100644
index 000000000..5b0420296
--- /dev/null
+++ b/priv/repo/migrations/20201222052839_add_index_to_notifications.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddIndexToNotifications do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists(index(:notifications, [:seen, :notified_at, :type, :inserted_at]))
+ end
+end