diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-02-25 17:46:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 17:46:00 +0000 |
commit | e66f099ca952ef47944c7bba3fd942f98245d39f (patch) | |
tree | fd0130a08c611abb71b6239181cd479f5703f6a7 /synapse/storage/prepare_database.py | |
parent | Merge worker apps into one. (#6964) (diff) | |
download | synapse-e66f099ca952ef47944c7bba3fd942f98245d39f.tar.xz |
Sanity-check database before running upgrades (#6982)
Some of the database deltas rely on `config.server_name` being set correctly, so we should check that it is before running the deltas. Fixes #6870.
Diffstat (limited to 'synapse/storage/prepare_database.py')
-rw-r--r-- | synapse/storage/prepare_database.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/synapse/storage/prepare_database.py b/synapse/storage/prepare_database.py index fc69c32a0a..6cb7d4b922 100644 --- a/synapse/storage/prepare_database.py +++ b/synapse/storage/prepare_database.py @@ -278,13 +278,17 @@ def _upgrade_existing_database( the current_version wasn't generated by applying those delta files. database_engine (DatabaseEngine) config (synapse.config.homeserver.HomeServerConfig|None): - application config, or None if we are connecting to an existing - database which we expect to be configured already + None if we are initialising a blank database, otherwise the application + config data_stores (list[str]): The names of the data stores to instantiate on the given database. is_empty (bool): Is this a blank database? I.e. do we need to run the upgrade portions of the delta scripts. """ + if is_empty: + assert not applied_delta_files + else: + assert config if current_version > SCHEMA_VERSION: raise ValueError( @@ -292,6 +296,13 @@ def _upgrade_existing_database( + "new for the server to understand" ) + # some of the deltas assume that config.server_name is set correctly, so now + # is a good time to run the sanity check. + if not is_empty and "main" in data_stores: + from synapse.storage.data_stores.main import check_database_before_upgrade + + check_database_before_upgrade(cur, database_engine, config) + start_ver = current_version if not upgraded: start_ver += 1 |