From 1c932e0778aacf7cd19285ecaf0abb6ecdf5ee04 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Jan 2021 10:57:51 +0000 Subject: [PATCH 1/3] Handle updating schema version without any deltas. This can happen when using a split out state database and we've upgraded the schema version without there being any changes in the state schema. --- synapse/storage/prepare_database.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/synapse/storage/prepare_database.py b/synapse/storage/prepare_database.py index f91a2eae7aa4..59fa18f397a5 100644 --- a/synapse/storage/prepare_database.py +++ b/synapse/storage/prepare_database.py @@ -489,11 +489,10 @@ def _upgrade_existing_database( (v, relative_path), ) - cur.execute("DELETE FROM schema_version") - cur.execute( - "INSERT INTO schema_version (version, upgraded) VALUES (?,?)", - (v, True), - ) + cur.execute("DELETE FROM schema_version") + cur.execute( + "INSERT INTO schema_version (version, upgraded) VALUES (?,?)", (v, True), + ) logger.info("Schema now up to date") From 4acfb5acb439dff2c55a9c8b3660eb776b8783f9 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Jan 2021 10:59:56 +0000 Subject: [PATCH 2/3] Newsfile --- changelog.d/9033.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9033.misc diff --git a/changelog.d/9033.misc b/changelog.d/9033.misc new file mode 100644 index 000000000000..e9a305c0e8ea --- /dev/null +++ b/changelog.d/9033.misc @@ -0,0 +1 @@ +Allow bumping schema version when using split out state database. From c5beb4c424d099b13962a71e6d7131f0dc5cd9eb Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Jan 2021 11:11:43 +0000 Subject: [PATCH 3/3] Update schema version *before* running deltas --- synapse/storage/prepare_database.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/synapse/storage/prepare_database.py b/synapse/storage/prepare_database.py index 59fa18f397a5..6684403a0a77 100644 --- a/synapse/storage/prepare_database.py +++ b/synapse/storage/prepare_database.py @@ -375,7 +375,16 @@ def _upgrade_existing_database( specific_engine_extensions = (".sqlite", ".postgres") for v in range(start_ver, SCHEMA_VERSION + 1): - logger.info("Applying schema deltas for v%d", v) + if not is_worker: + logger.info("Applying schema deltas for v%d", v) + + cur.execute("DELETE FROM schema_version") + cur.execute( + "INSERT INTO schema_version (version, upgraded) VALUES (?,?)", + (v, True), + ) + else: + logger.info("Checking schema deltas for v%d", v) # We need to search both the global and per data store schema # directories for schema updates. @@ -489,11 +498,6 @@ def _upgrade_existing_database( (v, relative_path), ) - cur.execute("DELETE FROM schema_version") - cur.execute( - "INSERT INTO schema_version (version, upgraded) VALUES (?,?)", (v, True), - ) - logger.info("Schema now up to date")