diff options
author | Alex Gleason <alex@alexgleason.me> | 2022-01-01 20:38:22 -0600 |
---|---|---|
committer | Alex Gleason <alex@alexgleason.me> | 2022-01-01 20:38:22 -0600 |
commit | bec555066d0a78670cf1dbc3d05e5647d242cb70 (patch) | |
tree | 33a2557be5c8eb713a5c9ddc8012d6e7982b8c89 | |
parent | 909f3bcdfe36591a7aac927af2f7fb50b9ce9dc6 (diff) | |
download | pleroma-bec555066d0a78670cf1dbc3d05e5647d242cb70.tar.gz |
ResolveActivityObjectConflicts: fix foreign key errors
-rw-r--r-- | lib/pleroma/migration_helper/object_id.ex | 5 | ||||
-rw-r--r-- | priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs | 10 |
2 files changed, 3 insertions, 12 deletions
diff --git a/lib/pleroma/migration_helper/object_id.ex b/lib/pleroma/migration_helper/object_id.ex index 4c8acffde..f122ff7b1 100644 --- a/lib/pleroma/migration_helper/object_id.ex +++ b/lib/pleroma/migration_helper/object_id.ex @@ -19,11 +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 -> - with {:ok, object} <- Repo.update(change(object, id: new_id)), + with {:ok, _} <- Repo.query("SET CONSTRAINTS ALL DEFERRED"), {:ok, _} <- update_object_fk(MessageReference, old_id, new_id), {:ok, _} <- update_object_fk(Delivery, old_id, new_id), {:ok, _} <- update_object_fk(HashtagObject, old_id, new_id), - {:ok, _} <- update_object_fk(DataMigrationFailedId, old_id, new_id, :record_id) do + {:ok, _} <- update_object_fk(DataMigrationFailedId, old_id, new_id, :record_id), + {:ok, object} <- Repo.update(change(object, id: new_id)) do {:ok, object} 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 28700d3d8..1e5a76ce9 100644 --- a/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs +++ b/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs @@ -18,11 +18,6 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do execute("LOCK TABLE deliveries") execute("LOCK TABLE hashtags_objects") - # Temporarily disable fkey constraints - disable_constraint("chat_message_references", "chat_message_references_object_id_fkey") - disable_constraint("deliveries", "deliveries_object_id_fkey") - disable_constraint("hashtags_objects", "hashtags_objects_object_id_fkey") - activity_conflict_query() |> Repo.stream() |> Stream.each(&update_object/1) @@ -43,9 +38,4 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do def down do :ok end - - # https://stackoverflow.com/a/48335239 - defp disable_constraint(table, constraint) do - execute("ALTER TABLE #{table} ALTER CONSTRAINT #{constraint} DEFERRABLE INITIALLY DEFERRED") - end end |