summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-08-27 09:46:13 +0100
committerOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-08-27 09:50:49 +0100
commit1ecd1a6a5fe95df7a726362c143320fab09373c2 (patch)
tree8de5bad5dd476acfcd1a6907769d9e488024bef1
parentAllow schema deltas to be engine-specific (diff)
downloadsynapse-1ecd1a6a5fe95df7a726362c143320fab09373c2.tar.xz
Use engine-specific delta SQL files rather than delta written in Python.
Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
-rw-r--r--synapse/storage/schema/delta/56/stats_separated2.py71
-rw-r--r--synapse/storage/schema/delta/56/stats_separated2.sql.postgres24
-rw-r--r--synapse/storage/schema/delta/56/stats_separated2.sql.sqlite27
3 files changed, 51 insertions, 71 deletions
diff --git a/synapse/storage/schema/delta/56/stats_separated2.py b/synapse/storage/schema/delta/56/stats_separated2.py
deleted file mode 100644
index 942d240010..0000000000
--- a/synapse/storage/schema/delta/56/stats_separated2.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2019 The Matrix.org Foundation C.I.C.
-#
-# 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.
-
-# This schema delta will be run after 'stats_separated1.sql' due to lexicographic
-# ordering. Note that it MUST be so.
-from synapse.storage.engines import PostgresEngine, Sqlite3Engine
-
-
-def _run_create_generic(stats_type, cursor, database_engine):
-    """
-    Creates the pertinent (partial, if supported) indices for one kind of stats.
-    Args:
-        stats_type: "room" or "user" - the type of stats
-        cursor: Database Cursor
-        database_engine: Database Engine
-    """
-    if isinstance(database_engine, Sqlite3Engine):
-        # even though SQLite >= 3.8 can support partial indices, we won't enable
-        # them, in case the SQLite database may be later used on another system.
-        # It's also the case that SQLite is only likely to be used in small
-        # deployments or testing, where the optimisations gained by use of a
-        # partial index are not a big concern.
-        cursor.execute(
-            """
-                CREATE INDEX IF NOT EXISTS %s_stats_not_complete
-                    ON %s_stats_current (completed_delta_stream_id, %s_id);
-            """
-            % (stats_type, stats_type, stats_type)
-        )
-    elif isinstance(database_engine, PostgresEngine):
-        # This partial index helps us with finding incomplete stats rows
-        cursor.execute(
-            """
-                CREATE INDEX IF NOT EXISTS %s_stats_not_complete
-                    ON %s_stats_current (%s_id)
-                    WHERE completed_delta_stream_id IS NULL;
-            """
-            % (stats_type, stats_type, stats_type)
-        )
-    else:
-        raise NotImplementedError("Unknown database engine.")
-
-
-def run_create(cursor, database_engine):
-    """
-    This function is called as part of the schema delta.
-    It will create indices - partial, if supported - for the new 'separated'
-    room & user statistics.
-    """
-    _run_create_generic("room", cursor, database_engine)
-    _run_create_generic("user", cursor, database_engine)
-
-
-def run_upgrade(cur, database_engine, config):
-    """
-    This function is run on a database upgrade (of a non-empty database).
-    We have no need to do anything specific here.
-    """
-    pass
diff --git a/synapse/storage/schema/delta/56/stats_separated2.sql.postgres b/synapse/storage/schema/delta/56/stats_separated2.sql.postgres
new file mode 100644
index 0000000000..0519fcff79
--- /dev/null
+++ b/synapse/storage/schema/delta/56/stats_separated2.sql.postgres
@@ -0,0 +1,24 @@
+/* Copyright 2019 The Matrix.org Foundation C.I.C.
+ *
+ * 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.
+ */
+
+-- These partial indices helps us with finding incomplete stats row
+CREATE INDEX IF NOT EXISTS room_stats_not_complete
+    ON room_stats_current (room_id)
+    WHERE completed_delta_stream_id IS NULL;
+
+CREATE INDEX IF NOT EXISTS user_stats_not_complete
+    ON user_stats_current (user_id)
+    WHERE completed_delta_stream_id IS NULL;
+
diff --git a/synapse/storage/schema/delta/56/stats_separated2.sql.sqlite b/synapse/storage/schema/delta/56/stats_separated2.sql.sqlite
new file mode 100644
index 0000000000..181f4ec5b9
--- /dev/null
+++ b/synapse/storage/schema/delta/56/stats_separated2.sql.sqlite
@@ -0,0 +1,27 @@
+/* Copyright 2019 The Matrix.org Foundation C.I.C.
+ *
+ * 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.
+ */
+
+-- even though SQLite >= 3.8 can support partial indices, we won't enable
+-- them, in case the SQLite database may be later used on another system.
+-- It's also the case that SQLite is only likely to be used in small
+-- deployments or testing, where the optimisations gained by use of a
+-- partial index are not a big concern.
+
+CREATE INDEX IF NOT EXISTS room_stats_not_complete
+    ON room_stats_current (completed_delta_stream_id, room_id);
+
+CREATE INDEX IF NOT EXISTS user_stats_not_complete
+    ON user_stats_current (completed_delta_stream_id, user_id);
+