diff --git a/synapse/storage/schema/__init__.py b/synapse/storage/schema/__init__.py index c4c4d7bcc4..8990bb0c17 100644 --- a/synapse/storage/schema/__init__.py +++ b/synapse/storage/schema/__init__.py @@ -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. """ diff --git a/synapse/storage/schema/main/delta/94/01_profile_updates.sql b/synapse/storage/schema/main/delta/94/01_profile_updates.sql new file mode 100644 index 0000000000..18a3deef6d --- /dev/null +++ b/synapse/storage/schema/main/delta/94/01_profile_updates.sql @@ -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: +-- . + +-- 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); diff --git a/synapse/storage/schema/main/delta/94/01_profile_updates_seq.sql.postgres b/synapse/storage/schema/main/delta/94/01_profile_updates_seq.sql.postgres new file mode 100644 index 0000000000..9abf79b68d --- /dev/null +++ b/synapse/storage/schema/main/delta/94/01_profile_updates_seq.sql.postgres @@ -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: +-- . + +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');