Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
905B

  1. defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do
  2. use Ecto.Migration
  3. import Ecto.Query
  4. alias Pleroma.Activity
  5. alias Pleroma.Bookmark
  6. alias Pleroma.Repo
  7. def up do
  8. query =
  9. from(u in "users",
  10. where: u.local == true,
  11. where: fragment("array_length(?, 1)", u.bookmarks) > 0,
  12. select: %{id: u.id, bookmarks: u.bookmarks}
  13. )
  14. Repo.stream(query)
  15. |> Enum.each(fn %{id: user_id, bookmarks: bookmarks} ->
  16. Enum.each(bookmarks, fn ap_id ->
  17. activity =
  18. ap_id
  19. |> Activity.create_by_object_ap_id()
  20. |> Repo.one()
  21. unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
  22. end)
  23. end)
  24. alter table(:users) do
  25. remove(:bookmarks)
  26. end
  27. end
  28. def down do
  29. alter table(:users) do
  30. add(:bookmarks, {:array, :string}, null: false, default: [])
  31. end
  32. end
  33. end