logo

pleroma

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

20210205145000_move_pinned_activities_into_pinned_objects.exs (903B)


  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.MovePinnedActivitiesIntoPinnedObjects do
  5. use Ecto.Migration
  6. import Ecto.Query
  7. alias Pleroma.Repo
  8. alias Pleroma.User
  9. def up do
  10. from(u in User)
  11. |> select([u], {u.id, fragment("?.pinned_activities", u)})
  12. |> Repo.stream()
  13. |> Stream.each(fn {user_id, pinned_activities_ids} ->
  14. pinned_activities = Pleroma.Activity.all_by_ids_with_object(pinned_activities_ids)
  15. pins =
  16. Map.new(pinned_activities, fn %{object: %{data: %{"id" => object_id}}} ->
  17. {object_id, NaiveDateTime.utc_now()}
  18. end)
  19. from(u in User, where: u.id == ^user_id)
  20. |> Repo.update_all(set: [pinned_objects: pins])
  21. end)
  22. |> Stream.run()
  23. end
  24. def down, do: :noop
  25. end