Migrations: Make them not fail for old databases
authorlain <lain@soykaf.club>
Thu, 20 Feb 2020 15:44:31 +0000 (16:44 +0100)
committerlain <lain@soykaf.club>
Thu, 20 Feb 2020 15:44:31 +0000 (16:44 +0100)
priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs
priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs
priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs

index 99102117f1cb99c6f4b32d8edc76f75781c491d5..c618ea3817dae9890a51fd04200e55df8a0c7796 100644 (file)
@@ -17,7 +17,11 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do
     Repo.stream(query)
     |> Enum.each(fn %{id: user_id, bookmarks: bookmarks} ->
       Enum.each(bookmarks, fn ap_id ->
-        activity = Activity.get_create_by_object_ap_id(ap_id)
+        activity =
+          ap_id
+          |> Activity.create_by_object_ap_id()
+          |> Repo.one()
+
         unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
       end)
     end)
index a5170d5215e801ccbbd99a4036eb4c545f97e3b3..44f9891b1cc06c103d7a329035b9b27d18640bf7 100644 (file)
@@ -1,7 +1,8 @@
 defmodule Pleroma.Repo.Migrations.AddFollowingAddressFromSourceData do
-  use Ecto.Migration
-  import Ecto.Query
   alias Pleroma.User
+  import Ecto.Query
+  require Logger
+  use Ecto.Migration
 
   def change do
     query =
@@ -19,6 +20,9 @@ defmodule Pleroma.Repo.Migrations.AddFollowingAddressFromSourceData do
           :following_address
         ])
         |> Pleroma.Repo.update()
+
+      user ->
+        Logger.warn("User #{user.id} / #{user.nickname} does not seem to have source_data")
     end)
   end
 end
index fc9bf70baf477ac311a6a7de488d67a15e0ab8d6..bbd50204416a1482bafa1ae55de3f8186c8ca1a8 100644 (file)
@@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do
   use Ecto.Migration
 
   def change do
+    execute("update users set info = '{}' where info is null")
+
     execute(
       "update users set info = safe_jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true"
     )