move to 2.5.5
[anni] / priv / repo / migrations / 20171212164525_fill_recipients_in_activities.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.FillRecipientsInActivities do
6   use Ecto.Migration
7   alias Pleroma.{Repo, Activity}
8
9   def up do
10     max = Repo.aggregate(Activity, :max, :id)
11
12     if max do
13       IO.puts("#{max} activities")
14       chunks = 0..round(max / 10_000)
15
16       Enum.each(chunks, fn i ->
17         min = i * 10_000
18         max = min + 10_000
19
20         execute("""
21         update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max};
22         """)
23         |> IO.inspect()
24       end)
25     end
26   end
27
28   def down, do: :ok
29 end