6dfa9371682c2f7fff72414a67f50d26bd4ff91d
[akkoma] / priv / repo / migrations / 20171212164525_fill_recipients_in_activities.exs
1 defmodule Pleroma.Repo.Migrations.FillRecipientsInActivities do
2 use Ecto.Migration
3 alias Pleroma.{Repo, Activity}
4
5 def up do
6 max = Repo.aggregate(Activity, :max, :id)
7
8 if max do
9 IO.puts("#{max} activities")
10 chunks = 0..round(max / 10_000)
11
12 Enum.each(chunks, fn i ->
13 min = i * 10_000
14 max = min + 10_000
15
16 execute("""
17 update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{
18 min
19 } and id <= #{max};
20 """)
21 |> IO.inspect()
22 end)
23 end
24 end
25
26 def down, do: :ok
27 end