summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/storage/event_push_actions.py6
-rw-r--r--synapse/storage/push_rule.py63
-rw-r--r--synapse/storage/pusher.py14
-rw-r--r--synapse/storage/room.py16
-rw-r--r--synapse/storage/transactions.py68
-rw-r--r--tests/handlers/test_presence.py1
-rw-r--r--tests/handlers/test_typing.py1
7 files changed, 41 insertions, 128 deletions
diff --git a/synapse/storage/event_push_actions.py b/synapse/storage/event_push_actions.py
index 5b44431ab9..d99171ee87 100644
--- a/synapse/storage/event_push_actions.py
+++ b/synapse/storage/event_push_actions.py
@@ -42,7 +42,7 @@ class EventPushActionsStore(SQLBaseStore):
         yield self.runInteraction(
             "set_actions_for_event_and_users",
             self._simple_insert_many_txn,
-            EventPushActionsTable.table_name,
+            "event_push_actions",
             values
         )
 
@@ -104,7 +104,3 @@ class EventPushActionsStore(SQLBaseStore):
             "remove_push_actions_for_event_id",
             f
         )
-
-
-class EventPushActionsTable(object):
-    table_name = "event_push_actions"
diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py
index 24d137f8ca..448009b4b6 100644
--- a/synapse/storage/push_rule.py
+++ b/synapse/storage/push_rule.py
@@ -27,11 +27,14 @@ class PushRuleStore(SQLBaseStore):
     @cachedInlineCallbacks()
     def get_push_rules_for_user(self, user_name):
         rows = yield self._simple_select_list(
-            table=PushRuleTable.table_name,
+            table="push_rules",
             keyvalues={
                 "user_name": user_name,
             },
-            retcols=PushRuleTable.fields,
+            retcols=(
+                "user_name", "rule_id", "priority_class", "priority",
+                "conditions", "actions",
+            ),
             desc="get_push_rules_enabled_for_user",
         )
 
@@ -44,11 +47,13 @@ class PushRuleStore(SQLBaseStore):
     @cachedInlineCallbacks()
     def get_push_rules_enabled_for_user(self, user_name):
         results = yield self._simple_select_list(
-            table=PushRuleEnableTable.table_name,
+            table="push_rules_enable",
             keyvalues={
                 'user_name': user_name
             },
-            retcols=PushRuleEnableTable.fields,
+            retcols=(
+                "user_name", "rule_id", "enabled",
+            ),
             desc="get_push_rules_enabled_for_user",
         )
         defer.returnValue({
@@ -65,12 +70,12 @@ class PushRuleStore(SQLBaseStore):
         def f(txn, user_ids_to_fetch):
             sql = (
                 "SELECT pr.*"
-                " FROM push_rules as pr "
-                " LEFT JOIN push_rules_enable as pre "
-                " ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id "
-                " WHERE pr.user_name "
+                " FROM push_rules AS pr"
+                " LEFT JOIN push_rules_enable AS pre"
+                " ON pr.user_name = pre.user_name AND pr.rule_id = pre.rule_id"
+                " WHERE pr.user_name"
                 " IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")"
-                " AND (pre.enabled is null or pre.enabled = 1)"
+                " AND (pre.enabled IS NULL OR pre.enabled = 1)"
                 " ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC"
             )
             txn.execute(sql, user_ids_to_fetch)
@@ -123,7 +128,7 @@ class PushRuleStore(SQLBaseStore):
 
         res = self._simple_select_one_txn(
             txn,
-            table=PushRuleTable.table_name,
+            table="push_rules",
             keyvalues={
                 "user_name": user_name,
                 "rule_id": relative_to_rule,
@@ -162,7 +167,7 @@ class PushRuleStore(SQLBaseStore):
         new_rule['priority'] = new_rule_priority
 
         sql = (
-            "SELECT COUNT(*) FROM " + PushRuleTable.table_name +
+            "SELECT COUNT(*) FROM push_rules"
             " WHERE user_name = ? AND priority_class = ? AND priority = ?"
         )
         txn.execute(sql, (user_name, priority_class, new_rule_priority))
@@ -171,7 +176,7 @@ class PushRuleStore(SQLBaseStore):
 
         # if there are conflicting rules, bump everything
         if num_conflicting:
-            sql = "UPDATE "+PushRuleTable.table_name+" SET priority = priority "
+            sql = "UPDATE push_rules SET priority = priority "
             if after:
                 sql += "-1"
             else:
@@ -194,7 +199,7 @@ class PushRuleStore(SQLBaseStore):
 
         self._simple_insert_txn(
             txn,
-            table=PushRuleTable.table_name,
+            table="push_rules",
             values=new_rule,
         )
 
@@ -202,7 +207,7 @@ class PushRuleStore(SQLBaseStore):
                                             priority_class, **kwargs):
         # find the highest priority rule in that class
         sql = (
-            "SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name +
+            "SELECT COUNT(*), MAX(priority) FROM push_rules"
             " WHERE user_name = ? and priority_class = ?"
         )
         txn.execute(sql, (user_name, priority_class))
@@ -229,7 +234,7 @@ class PushRuleStore(SQLBaseStore):
 
         self._simple_insert_txn(
             txn,
-            table=PushRuleTable.table_name,
+            table="push_rules",
             values=new_rule,
         )
 
@@ -245,7 +250,7 @@ class PushRuleStore(SQLBaseStore):
             rule_id (str): The rule_id of the rule to be deleted
         """
         yield self._simple_delete_one(
-            PushRuleTable.table_name,
+            "push_rules",
             {'user_name': user_name, 'rule_id': rule_id},
             desc="delete_push_rule",
         )
@@ -266,7 +271,7 @@ class PushRuleStore(SQLBaseStore):
         new_id = self._push_rules_enable_id_gen.get_next_txn(txn)
         self._simple_upsert_txn(
             txn,
-            PushRuleEnableTable.table_name,
+            "push_rules_enable",
             {'user_name': user_name, 'rule_id': rule_id},
             {'enabled': 1 if enabled else 0},
             {'id': new_id},
@@ -285,27 +290,3 @@ class RuleNotFoundException(Exception):
 
 class InconsistentRuleException(Exception):
     pass
-
-
-class PushRuleTable(object):
-    table_name = "push_rules"
-
-    fields = [
-        "id",
-        "user_name",
-        "rule_id",
-        "priority_class",
-        "priority",
-        "conditions",
-        "actions",
-    ]
-
-
-class PushRuleEnableTable(object):
-    table_name = "push_rules_enable"
-
-    fields = [
-        "user_name",
-        "rule_id",
-        "enabled"
-    ]
diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py
index b9568dad26..2b90d6c622 100644
--- a/synapse/storage/pusher.py
+++ b/synapse/storage/pusher.py
@@ -86,7 +86,7 @@ class PusherStore(SQLBaseStore):
         try:
             next_id = yield self._pushers_id_gen.get_next()
             yield self._simple_upsert(
-                PushersTable.table_name,
+                "pushers",
                 dict(
                     app_id=app_id,
                     pushkey=pushkey,
@@ -114,7 +114,7 @@ class PusherStore(SQLBaseStore):
     @defer.inlineCallbacks
     def delete_pusher_by_app_id_pushkey_user_name(self, app_id, pushkey, user_name):
         yield self._simple_delete_one(
-            PushersTable.table_name,
+            "pushers",
             {"app_id": app_id, "pushkey": pushkey, 'user_name': user_name},
             desc="delete_pusher_by_app_id_pushkey_user_name",
         )
@@ -122,7 +122,7 @@ class PusherStore(SQLBaseStore):
     @defer.inlineCallbacks
     def update_pusher_last_token(self, app_id, pushkey, user_name, last_token):
         yield self._simple_update_one(
-            PushersTable.table_name,
+            "pushers",
             {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
             {'last_token': last_token},
             desc="update_pusher_last_token",
@@ -132,7 +132,7 @@ class PusherStore(SQLBaseStore):
     def update_pusher_last_token_and_success(self, app_id, pushkey, user_name,
                                              last_token, last_success):
         yield self._simple_update_one(
-            PushersTable.table_name,
+            "pushers",
             {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
             {'last_token': last_token, 'last_success': last_success},
             desc="update_pusher_last_token_and_success",
@@ -142,12 +142,8 @@ class PusherStore(SQLBaseStore):
     def update_pusher_failing_since(self, app_id, pushkey, user_name,
                                     failing_since):
         yield self._simple_update_one(
-            PushersTable.table_name,
+            "pushers",
             {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
             {'failing_since': failing_since},
             desc="update_pusher_failing_since",
         )
-
-
-class PushersTable(object):
-    table_name = "pushers"
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 390bd78654..dc09a3aaba 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -49,7 +49,7 @@ class RoomStore(SQLBaseStore):
         """
         try:
             yield self._simple_insert(
-                RoomsTable.table_name,
+                "rooms",
                 {
                     "room_id": room_id,
                     "creator": room_creator_user_id,
@@ -70,9 +70,9 @@ class RoomStore(SQLBaseStore):
             A namedtuple containing the room information, or an empty list.
         """
         return self._simple_select_one(
-            table=RoomsTable.table_name,
+            table="rooms",
             keyvalues={"room_id": room_id},
-            retcols=RoomsTable.fields,
+            retcols=("room_id", "is_public", "creator"),
             desc="get_room",
             allow_none=True,
         )
@@ -275,13 +275,3 @@ class RoomStore(SQLBaseStore):
                     aliases.extend(e.content['aliases'])
 
         defer.returnValue((name, aliases))
-
-
-class RoomsTable(object):
-    table_name = "rooms"
-
-    fields = [
-        "room_id",
-        "is_public",
-        "creator"
-    ]
diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py
index b40a070b69..4475c451c1 100644
--- a/synapse/storage/transactions.py
+++ b/synapse/storage/transactions.py
@@ -16,8 +16,6 @@
 from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cached
 
-from collections import namedtuple
-
 from canonicaljson import encode_canonical_json
 import logging
 
@@ -50,12 +48,15 @@ class TransactionStore(SQLBaseStore):
     def _get_received_txn_response(self, txn, transaction_id, origin):
         result = self._simple_select_one_txn(
             txn,
-            table=ReceivedTransactionsTable.table_name,
+            table="received_transactions",
             keyvalues={
                 "transaction_id": transaction_id,
                 "origin": origin,
             },
-            retcols=ReceivedTransactionsTable.fields,
+            retcols=(
+                "transaction_id", "origin", "ts", "response_code", "response_json",
+                "has_been_referenced",
+            ),
             allow_none=True,
         )
 
@@ -79,7 +80,7 @@ class TransactionStore(SQLBaseStore):
         """
 
         return self._simple_insert(
-            table=ReceivedTransactionsTable.table_name,
+            table="received_transactions",
             values={
                 "transaction_id": transaction_id,
                 "origin": origin,
@@ -136,7 +137,7 @@ class TransactionStore(SQLBaseStore):
 
         self._simple_insert_txn(
             txn,
-            table=SentTransactions.table_name,
+            table="sent_transactions",
             values={
                 "id": next_id,
                 "transaction_id": transaction_id,
@@ -171,7 +172,7 @@ class TransactionStore(SQLBaseStore):
                        code, response_json):
         self._simple_update_one_txn(
             txn,
-            table=SentTransactions.table_name,
+            table="sent_transactions",
             keyvalues={
                 "transaction_id": transaction_id,
                 "destination": destination,
@@ -229,11 +230,11 @@ class TransactionStore(SQLBaseStore):
     def _get_destination_retry_timings(self, txn, destination):
         result = self._simple_select_one_txn(
             txn,
-            table=DestinationsTable.table_name,
+            table="destinations",
             keyvalues={
                 "destination": destination,
             },
-            retcols=DestinationsTable.fields,
+            retcols=("destination", "retry_last_ts", "retry_interval"),
             allow_none=True,
         )
 
@@ -304,52 +305,3 @@ class TransactionStore(SQLBaseStore):
 
         txn.execute(query, (self._clock.time_msec(),))
         return self.cursor_to_dict(txn)
-
-
-class ReceivedTransactionsTable(object):
-    table_name = "received_transactions"
-
-    fields = [
-        "transaction_id",
-        "origin",
-        "ts",
-        "response_code",
-        "response_json",
-        "has_been_referenced",
-    ]
-
-
-class SentTransactions(object):
-    table_name = "sent_transactions"
-
-    fields = [
-        "id",
-        "transaction_id",
-        "destination",
-        "ts",
-        "response_code",
-        "response_json",
-    ]
-
-    EntryType = namedtuple("SentTransactionsEntry", fields)
-
-
-class TransactionsToPduTable(object):
-    table_name = "transaction_id_to_pdu"
-
-    fields = [
-        "transaction_id",
-        "destination",
-        "pdu_id",
-        "pdu_origin",
-    ]
-
-
-class DestinationsTable(object):
-    table_name = "destinations"
-
-    fields = [
-        "destination",
-        "retry_last_ts",
-        "retry_interval",
-    ]
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index 15000aae0c..447a22b5fc 100644
--- a/tests/handlers/test_presence.py
+++ b/tests/handlers/test_presence.py
@@ -28,7 +28,6 @@ from synapse.api.constants import PresenceState
 from synapse.api.errors import SynapseError
 from synapse.handlers.presence import PresenceHandler, UserPresenceCache
 from synapse.streams.config import SourcePaginationConfig
-from synapse.storage.transactions import DestinationsTable
 from synapse.types import UserID
 
 OFFLINE = PresenceState.OFFLINE
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index 124bc10e0f..763c04d667 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -27,7 +27,6 @@ from ..utils import (
 from synapse.api.errors import AuthError
 from synapse.handlers.typing import TypingNotificationHandler
 
-from synapse.storage.transactions import DestinationsTable
 from synapse.types import UserID