aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-09-17 17:14:20 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-09-17 17:14:20 +0300
commitd9fb5bc08ad67b55d0cd25c1a0d7d3a740758427 (patch)
tree6303695147d01ab5e71e556f2b8f7725536e475f /priv
parent7cdbd91d83c02a79c22783ca489ef82e82b31a51 (diff)
parentcd93aa2aed6fda516d4fc2aabb44c5e178a6543d (diff)
downloadpleroma-d9fb5bc08ad67b55d0cd25c1a0d7d3a740758427.tar.gz
Merge remote-tracking branch 'remotes/origin/develop' into media-preview-proxy-nostream
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200914105638_delete_notification_without_activity.exs30
-rw-r--r--priv/repo/migrations/20200914105800_add_notification_constraints.exs23
2 files changed, 53 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs b/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs
new file mode 100644
index 000000000..9333fc5a1
--- /dev/null
+++ b/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs
@@ -0,0 +1,30 @@
+defmodule Pleroma.Repo.Migrations.DeleteNotificationWithoutActivity do
+ use Ecto.Migration
+
+ import Ecto.Query
+ alias Pleroma.Repo
+
+ def up do
+ from(
+ q in Pleroma.Notification,
+ left_join: c in assoc(q, :activity),
+ select: %{id: type(q.id, :integer)},
+ where: is_nil(c.id)
+ )
+ |> Repo.chunk_stream(1_000, :batches)
+ |> Stream.each(fn records ->
+ notification_ids = Enum.map(records, fn %{id: id} -> id end)
+
+ Repo.delete_all(
+ from(n in "notifications",
+ where: n.id in ^notification_ids
+ )
+ )
+ end)
+ |> Stream.run()
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200914105800_add_notification_constraints.exs b/priv/repo/migrations/20200914105800_add_notification_constraints.exs
new file mode 100644
index 000000000..a65c35fd0
--- /dev/null
+++ b/priv/repo/migrations/20200914105800_add_notification_constraints.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Repo.Migrations.AddNotificationConstraints do
+ use Ecto.Migration
+
+ def up do
+ drop(constraint(:notifications, "notifications_activity_id_fkey"))
+
+ alter table(:notifications) do
+ modify(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all),
+ null: false
+ )
+ end
+ end
+
+ def down do
+ drop(constraint(:notifications, "notifications_activity_id_fkey"))
+
+ alter table(:notifications) do
+ modify(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all),
+ null: true
+ )
+ end
+ end
+end