Explorar o código

Handle conflicting portal rows when migrating puppet UUID

Tulir Asokan %!s(int64=3) %!d(string=hai) anos
pai
achega
7d889bd2af
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      mautrix_signal/db/puppet.py

+ 6 - 1
mautrix_signal/db/puppet.py

@@ -67,7 +67,12 @@ class Puppet:
                                uuid, self.number)
             await conn.execute("UPDATE puppet SET uuid=$1 WHERE number=$2", uuid, self.number)
             uuid = str(uuid)
-            await conn.execute("UPDATE portal SET chat_id=$1 WHERE chat_id=$2", uuid, self.number)
+            try:
+                async with conn.transaction():
+                    await conn.execute("UPDATE portal SET chat_id=$1 WHERE chat_id=$2",
+                                       uuid, self.number)
+            except asyncpg.UniqueViolationError:
+                await conn.execute("DELETE FROM portal WHERE chat_id=$1", self.number)
             await conn.execute("UPDATE message SET sender=$1 WHERE sender=$2", uuid, self.number)
             await conn.execute("UPDATE reaction SET author=$1 WHERE author=$2", uuid, self.number)