summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/storage/e2e_room_keys.py9
-rw-r--r--synapse/storage/schema/delta/51/e2e_room_keys.sql3
2 files changed, 9 insertions, 3 deletions
diff --git a/synapse/storage/e2e_room_keys.py b/synapse/storage/e2e_room_keys.py
index 969f4aef9c..4d439bb164 100644
--- a/synapse/storage/e2e_room_keys.py
+++ b/synapse/storage/e2e_room_keys.py
@@ -193,7 +193,8 @@ class EndToEndRoomKeyStore(SQLBaseStore):
     @staticmethod
     def _get_current_version(txn, user_id):
         txn.execute(
-            "SELECT MAX(version) FROM e2e_room_keys_versions WHERE user_id=?",
+            "SELECT MAX(version) FROM e2e_room_keys_versions "
+            "WHERE user_id=? AND deleted=0",
             (user_id,)
         )
         row = txn.fetchone()
@@ -226,6 +227,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
                 keyvalues={
                     "user_id": user_id,
                     "version": this_version,
+                    "deleted": 0,
                 },
                 retcols=(
                     "version",
@@ -300,13 +302,16 @@ class EndToEndRoomKeyStore(SQLBaseStore):
             else:
                 this_version = version
 
-            return self._simple_delete_one_txn(
+            return self._simple_update_one_txn(
                 txn,
                 table="e2e_room_keys_versions",
                 keyvalues={
                     "user_id": user_id,
                     "version": this_version,
                 },
+                updatevalues={
+                    "deleted": 1,
+                }
             )
 
         return self.runInteraction(
diff --git a/synapse/storage/schema/delta/51/e2e_room_keys.sql b/synapse/storage/schema/delta/51/e2e_room_keys.sql
index 4531fd56ee..c0e66a697d 100644
--- a/synapse/storage/schema/delta/51/e2e_room_keys.sql
+++ b/synapse/storage/schema/delta/51/e2e_room_keys.sql
@@ -32,7 +32,8 @@ CREATE TABLE e2e_room_keys_versions (
     user_id TEXT NOT NULL,
     version TEXT NOT NULL,
     algorithm TEXT NOT NULL,
-    auth_data TEXT NOT NULL
+    auth_data TEXT NOT NULL,
+    deleted SMALLINT DEFAULT 0 NOT NULL
 );
 
 CREATE UNIQUE INDEX e2e_room_keys_versions_idx ON e2e_room_keys_versions(user_id, version);