Remove vapidPublicKey from Nodeinfo
[akkoma] / priv / repo / migrations / 20190414125034_migrate_old_bookmarks.exs
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.User
7 alias Pleroma.Repo
8
9 def up do
10 query =
11 from(u in "users",
12 where: u.local == true,
13 where: fragment("array_length(?, 1)", u.bookmarks) > 0,
14 select: %{id: u.id, bookmarks: u.bookmarks}
15 )
16
17 Repo.stream(query)
18 |> Enum.each(fn %{id: user_id, bookmarks: bookmarks} ->
19 Enum.each(bookmarks, fn ap_id ->
20 activity =
21 ap_id
22 |> Activity.create_by_object_ap_id()
23 |> Repo.one()
24
25 unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
26 end)
27 end)
28
29 alter table(:users) do
30 remove(:bookmarks)
31 end
32 end
33
34 def down do
35 alter table(:users) do
36 add(:bookmarks, {:array, :string}, null: false, default: [])
37 end
38 end
39 end