1930fc3cf30a3894ebc234093bc5b4a209311bf0
[akkoma] / priv / repo / migrations / 20190414125034_migrate_old_bookmarks.exs
1 defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do
2 use Ecto.Migration
3 alias Pleroma.Activity
4 alias Pleroma.Bookmark
5 alias Pleroma.User
6 alias Pleroma.Repo
7
8 def up do
9 Repo.all(User)
10 |> Enum.each(fn user ->
11 Enum.each(user.old_bookmarks, fn id ->
12 activity = Activity.get_create_by_object_ap_id(id)
13 {:ok, _} = Bookmark.create(user.id, activity.id)
14 end)
15 end)
16 end
17
18 def down do
19 execute("TRUNCATE TABLE bookmarks")
20 end
21 end