Schema for new profile updates stream table

We create a stream table dedicated to tracking profile updates. The sync
machinary can this stream to understand whether a profile update
needs to be included in a client's sync response.
This commit is contained in:
Andrew Morgan
2026-03-13 16:40:02 -04:00
parent 632c83eeae
commit d0b616ddce
3 changed files with 50 additions and 1 deletions
+4 -1
View File
@@ -19,7 +19,7 @@
#
#
SCHEMA_VERSION = 93 # remember to update the list below when updating
SCHEMA_VERSION = 94 # remember to update the list below when updating
"""Represents the expectations made by the codebase about the database schema
This should be incremented whenever the codebase changes its requirements on the
@@ -171,6 +171,9 @@ Changes in SCHEMA_VERSION = 92
Changes in SCHEMA_VERSION = 93
- MSC4140: Set delayed events to be uniquely identifiable by their delay ID.
Changes in SCHEMA_VERSION = 94
- MSC4429: Track updates to user profile fields via a new stream.
"""
@@ -0,0 +1,28 @@
--
-- This file is licensed under the Affero General Public License (AGPL) version 3.
--
-- Copyright (C) 2026 Element Creations Ltd.
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- See the GNU Affero General Public License for more details:
-- <https://www.gnu.org/licenses/agpl-3.0.html>.
-- Track updates to profile fields for MSC4429 legacy /sync.
CREATE TABLE profile_updates (
stream_id BIGINT NOT NULL PRIMARY KEY,
instance_name TEXT NOT NULL,
user_id TEXT NOT NULL,
field_name TEXT NOT NULL,
CONSTRAINT profile_updates_fk_users
FOREIGN KEY (user_id)
REFERENCES users(name) ON DELETE CASCADE
);
CREATE INDEX profile_updates_by_user ON profile_updates (user_id, stream_id);
CREATE INDEX profile_updates_by_field ON profile_updates (field_name, stream_id);
@@ -0,0 +1,18 @@
--
-- This file is licensed under the Affero General Public License (AGPL) version 3.
--
-- Copyright (C) 2026 Element Creations Ltd.
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- See the GNU Affero General Public License for more details:
-- <https://www.gnu.org/licenses/agpl-3.0.html>.
CREATE SEQUENCE profile_updates_sequence;
-- Synapse streams start at 2, because the default position is 1
-- so any item inserted at position 1 is ignored.
-- We have to use nextval not START WITH 2, see https://github.com/element-hq/synapse/issues/18712
SELECT nextval('profile_updates_sequence');