Backport fixes to sqlite upgrade from develop (#6578)

Only run prepare_database on connection for in-memory databases.

Fixes #6569.
This commit is contained in:
Richard van der Hoff 2019-12-20 10:46:46 +00:00 committed by GitHub
parent 03d3792f3c
commit 4caab0e95e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

1
changelog.d/6578.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.7.0 which caused an error on startup when upgrading from versions before 1.3.0.

View File

@ -25,6 +25,9 @@ class Sqlite3Engine(object):
def __init__(self, database_module, database_config): def __init__(self, database_module, database_config):
self.module = database_module self.module = database_module
database = database_config.get("args", {}).get("database")
self._is_in_memory = database in (None, ":memory:",)
# The current max state_group, or None if we haven't looked # The current max state_group, or None if we haven't looked
# in the DB yet. # in the DB yet.
self._current_state_group_id = None self._current_state_group_id = None
@ -59,7 +62,12 @@ class Sqlite3Engine(object):
return sql return sql
def on_new_connection(self, db_conn): def on_new_connection(self, db_conn):
if self._is_in_memory:
# In memory databases need to be rebuilt each time. Ideally we'd
# reuse the same connection as we do when starting up, but that
# would involve using adbapi before we have started the reactor.
prepare_database(db_conn, self, config=None) prepare_database(db_conn, self, config=None)
db_conn.create_function("rank", 1, _rank) db_conn.create_function("rank", 1, _rank)
def is_deadlock(self, error): def is_deadlock(self, error):