From 2c740a79d37b580f2dbbde378165d3383c4757ee Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Wed, 26 Aug 2020 20:16:23 +0100 Subject: [PATCH] Foreign key on rooms, SQL comment --- .../main/schema/delta/58/11recovery_after_outage.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synapse/storage/databases/main/schema/delta/58/11recovery_after_outage.sql b/synapse/storage/databases/main/schema/delta/58/11recovery_after_outage.sql index 5e331cc7c6..e3644367a2 100644 --- a/synapse/storage/databases/main/schema/delta/58/11recovery_after_outage.sql +++ b/synapse/storage/databases/main/schema/delta/58/11recovery_after_outage.sql @@ -18,7 +18,10 @@ -- This stores, for each (destination, room) pair, the event_id and stream_ordering -- of the latest event for that destination. CREATE TABLE IF NOT EXISTS destination_rooms ( - -- the destination in question + -- the destination in question. + -- Can not be a foreign key because rows in the `destinations` table will + -- only be created when we back off or when we successfully send a + -- transaction. destination TEXT NOT NULL, -- the ID of the room in question room_id TEXT NOT NULL, @@ -26,7 +29,8 @@ CREATE TABLE IF NOT EXISTS destination_rooms ( stream_ordering INTEGER, -- the event_id of the event event_id TEXT NOT NULL, - PRIMARY KEY (destination, room_id) + PRIMARY KEY (destination, room_id), + FOREIGN KEY (room_id) REFERENCES rooms (room_id) ); -- this column tracks the stream_ordering of the event that was most recently