Skip to content

Commit 87752c9

Browse files
committed
Add UNIQUE INDEX instead of replacing pkey
This prevents having to break DB compatibility / having to bump SCHEMA_COMPAT_VERSION. Use UNIQUE INDEX instead of ALTER TABLE for compatibility with SQLite.
1 parent f15b04d commit 87752c9

3 files changed

Lines changed: 8 additions & 47 deletions

File tree

synapse/storage/schema/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@
170170
- Cleaned up a trigger that was added in #18260 and then reverted.
171171
172172
Changes in SCHEMA_VERSION = 93
173-
- MSC4140: Remove `user_localpart` from the primary key of the `delayed_events` table,
174-
so that delayed events may be uniquely identified by their `delay_id` alone.
173+
- MSC4140: Set delayed events to be uniquely identifiable by their delay ID.
175174
"""
176175

177176

178177
SCHEMA_COMPAT_VERSION = (
179178
# Transitive links are no longer written to `event_auth_chain_links`
179+
# TODO: On the next compat bump, update the primary key of `delayed_events`
180180
84
181181
)
182182
"""Limit on how far the synapse codebase can be rolled back without breaking db compat

synapse/storage/schema/main/delta/93/01_add_delayed_events.sql.postgres renamed to synapse/storage/schema/main/delta/93/01_add_delayed_events.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
-- See the GNU Affero General Public License for more details:
1212
-- <https://www.gnu.org/licenses/agpl-3.0.html>.
1313

14-
-- Remove `user_localpart` from the primary key of the `delayed_events` table.
14+
-- Set delayed events to be uniquely identifiable by their delay_id.
1515

16-
ALTER TABLE delayed_events DROP CONSTRAINT delayed_events_pkey;
17-
ALTER TABLE delayed_events ADD PRIMARY KEY (delay_id);
16+
-- In practice, delay_ids are already unique because they are generated
17+
-- from cryptographically strong random strings.
18+
-- Therefore, adding this constraint is not expected to ever fail,
19+
-- despite the current pkey technically allowing non-unique delay_ids.
20+
CREATE UNIQUE INDEX delayed_events_idx ON delayed_events (delay_id);

synapse/storage/schema/main/delta/93/01_add_delayed_events.sql.sqlite

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)