Add option to modify HTTP pool size
[akkoma] / priv / repo / migrations / 20200914105638_delete_notification_without_activity.exs
1 defmodule Pleroma.Repo.Migrations.DeleteNotificationWithoutActivity do
2 use Ecto.Migration
3
4 import Ecto.Query
5 alias Pleroma.Repo
6
7 def up do
8 from(
9 q in Pleroma.Notification,
10 left_join: c in assoc(q, :activity),
11 select: %{id: type(q.id, :integer)},
12 where: is_nil(c.id)
13 )
14 |> Repo.chunk_stream(1_000, :batches)
15 |> Stream.each(fn records ->
16 notification_ids = Enum.map(records, fn %{id: id} -> id end)
17
18 Repo.delete_all(
19 from(n in "notifications",
20 where: n.id in ^notification_ids
21 )
22 )
23 end)
24 |> Stream.run()
25 end
26
27 def down do
28 :ok
29 end
30 end