logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

20171212164525_fill_recipients_in_activities.exs (748B)


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