summary refs log tree commit diff
path: root/synapse/storage/engines/postgres.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-29 11:42:28 +0100
committerErik Johnston <erik@matrix.org>2015-04-29 11:42:28 +0100
commit204132a998ec3be7069a9f2dada323bcdb217908 (patch)
treedaca5c26782846ba1ff66260f8fef4a246522b64 /synapse/storage/engines/postgres.py
parentimprove postgres blurb a bit (diff)
downloadsynapse-204132a998ec3be7069a9f2dada323bcdb217908.tar.xz
Check that postgres database has correct charset set
Diffstat (limited to 'synapse/storage/engines/postgres.py')
-rw-r--r--synapse/storage/engines/postgres.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py
index b8cca9b187..ca858daee9 100644
--- a/synapse/storage/engines/postgres.py
+++ b/synapse/storage/engines/postgres.py
@@ -15,12 +15,23 @@
 
 from synapse.storage import prepare_database
 
+from ._base import IncorrectDatabaseSetup
+
 
 class PostgresEngine(object):
     def __init__(self, database_module):
         self.module = database_module
         self.module.extensions.register_type(self.module.extensions.UNICODE)
 
+    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'"
+                % (rows[0][0],)
+            )
+
     def convert_param_style(self, sql):
         return sql.replace("?", "%s")