summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
committerMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
commit19167fd21fb74c10c95f61808d2b3c453ea36e8d (patch)
treed29e65d35d444b6e1b426fe44547585a2af2afcf /synapse/storage
parentminimal doc (diff)
parentMake postgres database error slightly more helpful (diff)
downloadsynapse-19167fd21fb74c10c95f61808d2b3c453ea36e8d.tar.xz
Merge pull request #135 from matrix-org/erikj/postgres_charset_check
Check that postgres database has correct charset set
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/engines/__init__.py4
-rw-r--r--synapse/storage/engines/_base.py18
-rw-r--r--synapse/storage/engines/postgres.py12
-rw-r--r--synapse/storage/engines/sqlite3.py3
4 files changed, 37 insertions, 0 deletions
diff --git a/synapse/storage/engines/__init__.py b/synapse/storage/engines/__init__.py
index eb76df7f01..bd3c8f9452 100644
--- a/synapse/storage/engines/__init__.py
+++ b/synapse/storage/engines/__init__.py
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from ._base import IncorrectDatabaseSetup
 from .postgres import PostgresEngine
 from .sqlite3 import Sqlite3Engine
 
@@ -35,3 +36,6 @@ def create_engine(name):
     raise RuntimeError(
         "Unsupported database engine '%s'" % (name,)
     )
+
+
+__all__ = ["create_engine", "IncorrectDatabaseSetup"]
diff --git a/synapse/storage/engines/_base.py b/synapse/storage/engines/_base.py
new file mode 100644
index 0000000000..0b549d314b
--- /dev/null
+++ b/synapse/storage/engines/_base.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+# Copyright 2015 OpenMarket Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class IncorrectDatabaseSetup(RuntimeError):
+    pass
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py
index b8cca9b187..7125f66f01 100644
--- a/synapse/storage/engines/postgres.py
+++ b/synapse/storage/engines/postgres.py
@@ -15,12 +15,24 @@
 
 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'\n"
+                "See docs/postgres.rst for more information."
+                % (rows[0][0],)
+            )
+
     def convert_param_style(self, sql):
         return sql.replace("?", "%s")
 
diff --git a/synapse/storage/engines/sqlite3.py b/synapse/storage/engines/sqlite3.py
index f62d5d1205..7b49157cbd 100644
--- a/synapse/storage/engines/sqlite3.py
+++ b/synapse/storage/engines/sqlite3.py
@@ -20,6 +20,9 @@ class Sqlite3Engine(object):
     def __init__(self, database_module):
         self.module = database_module
 
+    def check_database(self, txn):
+        pass
+
     def convert_param_style(self, sql):
         return sql