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