diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-09-14 14:08:12 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-09-14 14:08:12 +0300 |
commit | 3e53ab4e98e6294f593f2185998f555ccd6fee73 (patch) | |
tree | d458582b96dcfe7050e992e3bc601e97dd14231f /priv | |
parent | 2937e3095ab9208b2aea1f42792ab99b1b4252d7 (diff) | |
download | pleroma-3e53ab4e98e6294f593f2185998f555ccd6fee73.tar.gz pleroma-3e53ab4e98e6294f593f2185998f555ccd6fee73.zip |
added notification constraints
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20200914105638_delete_notification_without_activity.exs | 30 | ||||
-rw-r--r-- | priv/repo/migrations/20200914105800_add_notification_constraints.exs | 23 |
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..f5b339101 --- /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, :bacthes) + |> 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 |