summary refs log tree commit diff
path: root/synapse/storage/engines/postgres.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-01-09 17:21:30 +0000
committerRichard van der Hoff <richard@matrix.org>2020-01-09 18:05:50 +0000
commite97d1cf0014668b9d4883d4175b783088444b24b (patch)
treef490b673ca4de0c7bd3ed53081f7f92a84394de2 /synapse/storage/engines/postgres.py
parentAllow admin users to create or modify users without a shared secret (#6495) (diff)
downloadsynapse-e97d1cf0014668b9d4883d4175b783088444b24b.tar.xz
Modify check_database to take a connection rather than a cursor
We might not need the cursor at all.
Diffstat (limited to 'synapse/storage/engines/postgres.py')
-rw-r--r--synapse/storage/engines/postgres.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py
index b7c4eda338..ba19785fd7 100644
--- a/synapse/storage/engines/postgres.py
+++ b/synapse/storage/engines/postgres.py
@@ -32,14 +32,15 @@ class PostgresEngine(object):
         self.synchronous_commit = database_config.get("synchronous_commit", True)
         self._version = None  # unknown as yet
 
-    def check_database(self, txn):
-        txn.execute("SHOW SERVER_ENCODING")
-        rows = txn.fetchall()
-        if rows and rows[0][0] != "UTF8":
-            raise IncorrectDatabaseSetup(
-                "Database has incorrect encoding: '%s' instead of 'UTF8'\n"
-                "See docs/postgres.rst for more information." % (rows[0][0],)
-            )
+    def check_database(self, db_conn):
+        with db_conn.cursor() as txn:
+            txn.execute("SHOW SERVER_ENCODING")
+            rows = txn.fetchall()
+            if rows and rows[0][0] != "UTF8":
+                raise IncorrectDatabaseSetup(
+                    "Database has incorrect encoding: '%s' instead of 'UTF8'\n"
+                    "See docs/postgres.rst for more information." % (rows[0][0],)
+                )
 
     def convert_param_style(self, sql):
         return sql.replace("?", "%s")