0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 19:23:51 +01:00

Use context manager with db conn to correctly commit and rollback

This commit is contained in:
Erik Johnston 2015-03-04 13:43:17 +00:00
parent 8c8354e85a
commit 640e53935d

View file

@ -55,7 +55,7 @@ import re
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Remember to update this number every time an change is made to database # Remember to update this number every time a change is made to database
# schema files, so the users will be informed on server restarts. # schema files, so the users will be informed on server restarts.
SCHEMA_VERSION = 14 SCHEMA_VERSION = 14
@ -583,6 +583,7 @@ def prepare_database(db_conn):
"""Prepares a database for usage. Will either create all necessary tables """Prepares a database for usage. Will either create all necessary tables
or upgrade from an older schema version. or upgrade from an older schema version.
""" """
with db_conn:
cur = db_conn.cursor() cur = db_conn.cursor()
version_info = _get_or_create_schema_state(cur) version_info = _get_or_create_schema_state(cur)
@ -593,7 +594,6 @@ def prepare_database(db_conn):
_setup_new_database(cur) _setup_new_database(cur)
cur.execute("PRAGMA user_version = %d" % (SCHEMA_VERSION,)) cur.execute("PRAGMA user_version = %d" % (SCHEMA_VERSION,))
db_conn.commit()
cur.close() cur.close()