Merge develop
[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 if max do
8 IO.puts("#{max} activities")
9 chunks = 0..(round(max / 10_000))
10
11 Enum.each(chunks, fn (i) ->
12 min = i * 10_000
13 max = min + 10_000
14 execute("""
15 update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max};
16 """)
17 |> IO.inspect
18 end)
19 end
20 end
21
22 def down, do: :ok
23 end