logo

pleroma

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

20190710125158_add_following_address_from_source_data.exs (893B)


  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.AddFollowingAddressFromSourceData do
  5. alias Pleroma.User
  6. import Ecto.Query
  7. require Logger
  8. use Ecto.Migration
  9. def change do
  10. query =
  11. User.Query.build(%{
  12. external: true,
  13. legacy_active: true,
  14. order_by: :id
  15. })
  16. |> select([u], struct(u, [:id, :ap_id, :info]))
  17. Pleroma.Repo.stream(query)
  18. |> Enum.each(fn
  19. %{info: %{source_data: source_data}} = user ->
  20. Ecto.Changeset.cast(user, %{following_address: source_data["following"]}, [
  21. :following_address
  22. ])
  23. |> Pleroma.Repo.update()
  24. user ->
  25. Logger.warning("User #{user.id} / #{user.nickname} does not seem to have source_data")
  26. end)
  27. end
  28. end