summary refs log tree commit diff
path: root/synapse/storage/schema
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-07-10 16:24:42 +0100
committerGitHub <noreply@github.com>2023-07-10 16:24:42 +0100
commite55a9b3e41e73f34fda781b9374935c4623f7ea9 (patch)
tree6cfa8859ae42ed28cf12470586cd3a7539e1da5f /synapse/storage/schema
parentFix building rust with nightly (#15906) (diff)
downloadsynapse-e55a9b3e41e73f34fda781b9374935c4623f7ea9.tar.xz
Fix downgrading to previous version of Synapse (#15907)
We do this by marking the constraint as deferrable.
Diffstat (limited to 'synapse/storage/schema')
-rw-r--r--synapse/storage/schema/main/delta/78/03event_extremities_constraints.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py b/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py
index f12e2a8f3e..bf8c57dbe8 100644
--- a/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py
+++ b/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py
@@ -28,19 +28,25 @@ FORWARD_EXTREMITIES_TABLE_SCHEMA = """
         event_id TEXT NOT NULL,
         room_id TEXT NOT NULL,
         UNIQUE (event_id, room_id),
-        CONSTRAINT event_forward_extremities_event_id FOREIGN KEY (event_id) REFERENCES events (event_id)
+        CONSTRAINT event_forward_extremities_event_id FOREIGN KEY (event_id) REFERENCES events (event_id) DEFERRABLE INITIALLY DEFERRED
     )
 """
 
 
 def run_create(cur: LoggingTransaction, database_engine: BaseDatabaseEngine) -> None:
+    # We mark this as a deferred constraint, as the previous version of Synapse
+    # inserted the event into the forward extremities *before* the events table.
+    # By marking as deferred we ensure that downgrading to the previous version
+    # will continue to work.
     run_validate_constraint_and_delete_rows_schema_delta(
         cur,
         ordering=7803,
         update_name="event_forward_extremities_event_id_foreign_key_constraint_update",
         table="event_forward_extremities",
         constraint_name="event_forward_extremities_event_id",
-        constraint=ForeignKeyConstraint("events", [("event_id", "event_id")]),
+        constraint=ForeignKeyConstraint(
+            "events", [("event_id", "event_id")], deferred=True
+        ),
         sqlite_table_name="event_forward_extremities2",
         sqlite_table_schema=FORWARD_EXTREMITIES_TABLE_SCHEMA,
     )