Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Backport fixes to sqlite upgrade from develop (#6578)
Browse files Browse the repository at this point in the history
Only run prepare_database on connection for in-memory databases.

Fixes #6569.
  • Loading branch information
richvdh authored Dec 20, 2019
1 parent 03d3792 commit 4caab0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/6578.bugfix
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 9 additions & 1 deletion synapse/storage/engines/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Sqlite3Engine(object):
def __init__(self, database_module, database_config):
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
# in the DB yet.
self._current_state_group_id = None
Expand Down Expand Up @@ -59,7 +62,12 @@ def convert_param_style(self, sql):
return sql

def on_new_connection(self, db_conn):
prepare_database(db_conn, self, config=None)
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)

db_conn.create_function("rank", 1, _rank)

def is_deadlock(self, error):
Expand Down

0 comments on commit 4caab0e

Please sign in to comment.