X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=priv%2Frepo%2Fmigrations%2F20190414125034_migrate_old_bookmarks.exs;h=f3928a14962ce86b0bb0daeb03e320dd2d2265ec;hb=24eecc3cb4a35376124b1fc792183d8b8dd0a9cc;hp=ebe69696e6ff68f797b2bffecd1504d600d05367;hpb=002ea343f8c6dc9669bce91942f835a2c7cc6ae7;p=akkoma diff --git a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs index ebe69696e..f3928a149 100644 --- a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs +++ b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs @@ -6,7 +6,7 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do alias Pleroma.User alias Pleroma.Repo - def change do + def up do query = from(u in User, where: u.local == true, @@ -18,7 +18,7 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do |> Enum.each(fn %{id: user_id, bookmarks: bookmarks} -> Enum.each(bookmarks, fn ap_id -> activity = Activity.get_create_by_object_ap_id(ap_id) - {:ok, _} = Bookmark.create(user_id, activity.id) + unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id) end) end) @@ -26,4 +26,10 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do remove(:bookmarks) end end + + def down do + alter table(:users) do + add(:bookmarks, {:array, :string}, null: false, default: []) + end + end end