diff options
-rw-r--r-- | lib/pleroma/migration_helper/object_id.ex | 14 | ||||
-rw-r--r-- | priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs | 8 |
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/pleroma/migration_helper/object_id.ex b/lib/pleroma/migration_helper/object_id.ex index 170c15666..44af99c8d 100644 --- a/lib/pleroma/migration_helper/object_id.ex +++ b/lib/pleroma/migration_helper/object_id.ex @@ -19,24 +19,12 @@ defmodule Pleroma.MigrationHelper.ObjectId do @doc "Change an object's ID including all references." def change_id(%Object{id: old_id} = object, new_id) do Repo.transaction(fn -> - # Temporarily disable triggers (and by consequence, fkey constraints) - # https://stackoverflow.com/a/18709987 - Repo.query!("SET session_replication_role = replica") - - # Update foreign keys update_object_fk(MessageReference, old_id, new_id) update_object_fk(Delivery, old_id, new_id) update_object_fk(HashtagObject, old_id, new_id) update_object_fk(DataMigrationFailedId, old_id, new_id, :record_id) - # Update the object - object = Repo.update!(change(object, id: new_id)) - - # Re-enable triggers - Repo.query!("SET session_replication_role = DEFAULT") - - # Return the object - object + Repo.update!(change(object, id: new_id)) end) end diff --git a/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs b/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs index 8c1172332..71bca1cbe 100644 --- a/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs +++ b/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs @@ -18,10 +18,18 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do execute("LOCK TABLE deliveries") execute("LOCK TABLE hashtags_objects") + # Temporarily disable triggers (and by consequence, fkey constraints) + # https://stackoverflow.com/a/18709987 + Repo.query!("SET session_replication_role = replica") + + # Update conflicting objects activity_conflict_query() |> Repo.stream() |> Stream.each(&update_object!/1) |> Stream.run() + + # Re-enable triggers + Repo.query!("SET session_replication_role = DEFAULT") end # Get only objects with a conflicting activity ID. |