소스 검색

Drop weird message rows without corresponding puppet row

Tulir Asokan 2 년 전
부모
커밋
2798e463ca
1개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      mautrix_signal/db/upgrade/v11_drop_number_support.py

+ 18 - 0
mautrix_signal/db/upgrade/v11_drop_number_support.py

@@ -23,6 +23,24 @@ async def upgrade_v11(conn: Connection, scheme: Scheme) -> None:
     await conn.execute("DELETE FROM portal WHERE chat_id LIKE '+%'")
     await conn.execute("DELETE FROM message WHERE sender LIKE '+%'")
     await conn.execute("DELETE FROM reaction WHERE author LIKE '+%'")
+    await conn.execute(
+        """
+        DELETE FROM message WHERE sender IN (
+            SELECT DISTINCT(message.sender) FROM message
+            LEFT JOIN puppet ON message.sender=puppet.uuid::text
+            WHERE puppet.uuid IS NULL
+        )
+        """
+    )
+    await conn.execute(
+        """
+        DELETE FROM reaction WHERE author IN (
+            SELECT DISTINCT(reaction.author) FROM reaction
+            LEFT JOIN puppet ON reaction.author=puppet.uuid::text
+            WHERE puppet.uuid IS NULL
+        )
+        """
+    )
     await conn.execute("DELETE FROM puppet WHERE uuid IS NULL")
     if scheme in (Scheme.POSTGRES, Scheme.COCKROACH):
         await conn.execute(