logo

pleroma

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

20240904142434_assign_app_user.exs (563B)


  1. defmodule Pleroma.Repo.Migrations.AssignAppUser do
  2. use Ecto.Migration
  3. import Ecto.Query
  4. alias Pleroma.Repo
  5. alias Pleroma.Web.OAuth.App
  6. alias Pleroma.Web.OAuth.Token
  7. def up do
  8. Token
  9. |> where([t], not is_nil(t.user_id))
  10. |> group_by([t], t.app_id)
  11. |> select([t], %{app_id: t.app_id, id: min(t.id)})
  12. |> order_by(asc: :app_id)
  13. |> Repo.stream()
  14. |> Stream.each(fn %{id: id} ->
  15. token = Token.Query.get_by_id(id) |> Repo.one()
  16. App.maybe_update_owner(token)
  17. end)
  18. |> Stream.run()
  19. end
  20. def down, do: :ok
  21. end