mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 03:33:51 +01:00
Bump DB version to 79 since synapse v1.88 was already there (#15998)
This commit is contained in:
parent
dbee081d14
commit
8ebfd577e2
7 changed files with 22 additions and 16 deletions
1
changelog.d/15998.bugfix
Normal file
1
changelog.d/15998.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Internal changelog to be removed.
|
|
@ -12,7 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
SCHEMA_VERSION = 78 # remember to update the list below when updating
|
SCHEMA_VERSION = 79 # remember to update the list below when updating
|
||||||
"""Represents the expectations made by the codebase about the database schema
|
"""Represents the expectations made by the codebase about the database schema
|
||||||
|
|
||||||
This should be incremented whenever the codebase changes its requirements on the
|
This should be incremented whenever the codebase changes its requirements on the
|
||||||
|
@ -106,6 +106,10 @@ Changes in SCHEMA_VERSION = 77
|
||||||
|
|
||||||
Changes in SCHEMA_VERSION = 78
|
Changes in SCHEMA_VERSION = 78
|
||||||
- Validate check (full_user_id IS NOT NULL) on tables profiles and user_filters
|
- Validate check (full_user_id IS NOT NULL) on tables profiles and user_filters
|
||||||
|
|
||||||
|
Changes in SCHEMA_VERSION = 79
|
||||||
|
- Add tables to handle in DB read-write locks.
|
||||||
|
- Add some mitigations for a painful race between foreground and background updates, cf #15677.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
-- A table to track whether a lock is currently acquired, and if so whether its
|
-- A table to track whether a lock is currently acquired, and if so whether its
|
||||||
-- in read or write mode.
|
-- in read or write mode.
|
||||||
CREATE TABLE worker_read_write_locks_mode (
|
CREATE TABLE IF NOT EXISTS worker_read_write_locks_mode (
|
||||||
lock_name TEXT NOT NULL,
|
lock_name TEXT NOT NULL,
|
||||||
lock_key TEXT NOT NULL,
|
lock_key TEXT NOT NULL,
|
||||||
-- Whether this lock is in read (false) or write (true) mode
|
-- Whether this lock is in read (false) or write (true) mode
|
||||||
|
@ -55,14 +55,14 @@ CREATE TABLE worker_read_write_locks_mode (
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Ensure that we can only have one row per lock
|
-- Ensure that we can only have one row per lock
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_mode_key ON worker_read_write_locks_mode (lock_name, lock_key);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_mode_key ON worker_read_write_locks_mode (lock_name, lock_key);
|
||||||
-- We need this (redundant) constraint so that we can have a foreign key
|
-- We need this (redundant) constraint so that we can have a foreign key
|
||||||
-- constraint against this table.
|
-- constraint against this table.
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_mode_type ON worker_read_write_locks_mode (lock_name, lock_key, write_lock);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_mode_type ON worker_read_write_locks_mode (lock_name, lock_key, write_lock);
|
||||||
|
|
||||||
|
|
||||||
-- A table to track who has currently acquired a given lock.
|
-- A table to track who has currently acquired a given lock.
|
||||||
CREATE TABLE worker_read_write_locks (
|
CREATE TABLE IF NOT EXISTS worker_read_write_locks (
|
||||||
lock_name TEXT NOT NULL,
|
lock_name TEXT NOT NULL,
|
||||||
lock_key TEXT NOT NULL,
|
lock_key TEXT NOT NULL,
|
||||||
-- We write the instance name to ease manual debugging, we don't ever read
|
-- We write the instance name to ease manual debugging, we don't ever read
|
||||||
|
@ -84,9 +84,9 @@ CREATE TABLE worker_read_write_locks (
|
||||||
FOREIGN KEY (lock_name, lock_key, write_lock) REFERENCES worker_read_write_locks_mode (lock_name, lock_key, write_lock)
|
FOREIGN KEY (lock_name, lock_key, write_lock) REFERENCES worker_read_write_locks_mode (lock_name, lock_key, write_lock)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_key ON worker_read_write_locks (lock_name, lock_key, token);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_key ON worker_read_write_locks (lock_name, lock_key, token);
|
||||||
-- Ensures that only one instance can acquire a lock in write mode at a time.
|
-- Ensures that only one instance can acquire a lock in write mode at a time.
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_write ON worker_read_write_locks (lock_name, lock_key) WHERE write_lock;
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_write ON worker_read_write_locks (lock_name, lock_key) WHERE write_lock;
|
||||||
|
|
||||||
|
|
||||||
-- Add a foreign key constraint to ensure that if a lock is in
|
-- Add a foreign key constraint to ensure that if a lock is in
|
||||||
|
@ -97,5 +97,6 @@ CREATE UNIQUE INDEX worker_read_write_locks_write ON worker_read_write_locks (lo
|
||||||
-- We only add to PostgreSQL as SQLite does not support adding constraints
|
-- We only add to PostgreSQL as SQLite does not support adding constraints
|
||||||
-- after table creation, and so doesn't support "circular" foreign key
|
-- after table creation, and so doesn't support "circular" foreign key
|
||||||
-- constraints.
|
-- constraints.
|
||||||
|
ALTER TABLE worker_read_write_locks_mode DROP CONSTRAINT IF EXISTS worker_read_write_locks_mode_foreign;
|
||||||
ALTER TABLE worker_read_write_locks_mode ADD CONSTRAINT worker_read_write_locks_mode_foreign
|
ALTER TABLE worker_read_write_locks_mode ADD CONSTRAINT worker_read_write_locks_mode_foreign
|
||||||
FOREIGN KEY (lock_name, lock_key, token) REFERENCES worker_read_write_locks(lock_name, lock_key, token) DEFERRABLE INITIALLY DEFERRED;
|
FOREIGN KEY (lock_name, lock_key, token) REFERENCES worker_read_write_locks(lock_name, lock_key, token) DEFERRABLE INITIALLY DEFERRED;
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
-- A table to track whether a lock is currently acquired, and if so whether its
|
-- A table to track whether a lock is currently acquired, and if so whether its
|
||||||
-- in read or write mode.
|
-- in read or write mode.
|
||||||
CREATE TABLE worker_read_write_locks_mode (
|
CREATE TABLE IF NOT EXISTS worker_read_write_locks_mode (
|
||||||
lock_name TEXT NOT NULL,
|
lock_name TEXT NOT NULL,
|
||||||
lock_key TEXT NOT NULL,
|
lock_key TEXT NOT NULL,
|
||||||
-- Whether this lock is in read (false) or write (true) mode
|
-- Whether this lock is in read (false) or write (true) mode
|
||||||
|
@ -38,14 +38,14 @@ CREATE TABLE worker_read_write_locks_mode (
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Ensure that we can only have one row per lock
|
-- Ensure that we can only have one row per lock
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_mode_key ON worker_read_write_locks_mode (lock_name, lock_key);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_mode_key ON worker_read_write_locks_mode (lock_name, lock_key);
|
||||||
-- We need this (redundant) constraint so that we can have a foreign key
|
-- We need this (redundant) constraint so that we can have a foreign key
|
||||||
-- constraint against this table.
|
-- constraint against this table.
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_mode_type ON worker_read_write_locks_mode (lock_name, lock_key, write_lock);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_mode_type ON worker_read_write_locks_mode (lock_name, lock_key, write_lock);
|
||||||
|
|
||||||
|
|
||||||
-- A table to track who has currently acquired a given lock.
|
-- A table to track who has currently acquired a given lock.
|
||||||
CREATE TABLE worker_read_write_locks (
|
CREATE TABLE IF NOT EXISTS worker_read_write_locks (
|
||||||
lock_name TEXT NOT NULL,
|
lock_name TEXT NOT NULL,
|
||||||
lock_key TEXT NOT NULL,
|
lock_key TEXT NOT NULL,
|
||||||
-- We write the instance name to ease manual debugging, we don't ever read
|
-- We write the instance name to ease manual debugging, we don't ever read
|
||||||
|
@ -67,6 +67,6 @@ CREATE TABLE worker_read_write_locks (
|
||||||
FOREIGN KEY (lock_name, lock_key, write_lock) REFERENCES worker_read_write_locks_mode (lock_name, lock_key, write_lock)
|
FOREIGN KEY (lock_name, lock_key, write_lock) REFERENCES worker_read_write_locks_mode (lock_name, lock_key, write_lock)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_key ON worker_read_write_locks (lock_name, lock_key, token);
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_key ON worker_read_write_locks (lock_name, lock_key, token);
|
||||||
-- Ensures that only one instance can acquire a lock in write mode at a time.
|
-- Ensures that only one instance can acquire a lock in write mode at a time.
|
||||||
CREATE UNIQUE INDEX worker_read_write_locks_write ON worker_read_write_locks (lock_name, lock_key) WHERE write_lock;
|
CREATE UNIQUE INDEX IF NOT EXISTS worker_read_write_locks_write ON worker_read_write_locks (lock_name, lock_key) WHERE write_lock;
|
|
@ -37,17 +37,17 @@ def run_create(
|
||||||
# after the background update has finished
|
# after the background update has finished
|
||||||
if res:
|
if res:
|
||||||
drop_cse_sql = """
|
drop_cse_sql = """
|
||||||
ALTER TABLE current_state_events DROP CONSTRAINT event_stream_ordering_fkey
|
ALTER TABLE current_state_events DROP CONSTRAINT IF EXISTS event_stream_ordering_fkey
|
||||||
"""
|
"""
|
||||||
cur.execute(drop_cse_sql)
|
cur.execute(drop_cse_sql)
|
||||||
|
|
||||||
drop_lcm_sql = """
|
drop_lcm_sql = """
|
||||||
ALTER TABLE local_current_membership DROP CONSTRAINT event_stream_ordering_fkey
|
ALTER TABLE local_current_membership DROP CONSTRAINT IF EXISTS event_stream_ordering_fkey
|
||||||
"""
|
"""
|
||||||
cur.execute(drop_lcm_sql)
|
cur.execute(drop_lcm_sql)
|
||||||
|
|
||||||
drop_rm_sql = """
|
drop_rm_sql = """
|
||||||
ALTER TABLE room_memberships DROP CONSTRAINT event_stream_ordering_fkey
|
ALTER TABLE room_memberships DROP CONSTRAINT IF EXISTS event_stream_ordering_fkey
|
||||||
"""
|
"""
|
||||||
cur.execute(drop_rm_sql)
|
cur.execute(drop_rm_sql)
|
||||||
|
|
Loading…
Reference in a new issue