Philipp Hörist pushed to branch master at gajim / gajim


Commits:
5a83b0b8 by Philipp Hörist at 2025-11-03T00:18:21+01:00
cfix: Database: Fix messages with wrong type

- - - - -


2 changed files:

- gajim/common/storage/archive/migration.py
- gajim/common/storage/archive/storage.py


Changes:

=====================================
gajim/common/storage/archive/migration.py
=====================================
@@ -123,6 +123,8 @@ def __init__(self, archive: AlchemyStorage, user_version: 
int) -> None:
             self._v13()
         if user_version < 14:
             self._v14()
+        if user_version < 15:
+            self._v15()
 
         app.ged.raise_event(DBMigrationFinished())
 
@@ -315,6 +317,29 @@ def _v14(self) -> None:
         ]
         self._execute_multiple(statements)
 
+    def _v15(self) -> None:
+        # In the past some PM messages were not correctly discovered
+        # Find them and set the type and resource
+        unique_remotes_stmt = (
+            
sa.select(mod.Message.fk_remote_pk).distinct().where(mod.Message.type == 3)
+        )
+        remotes_stmt = sa.select(mod.Remote).where(
+            mod.Remote.pk.in_(unique_remotes_stmt.scalar_subquery())
+        )
+
+        with self._archive.get_session() as s:
+            remotes = s.execute(remotes_stmt).scalars().all()
+            for remote in remotes:
+                stmt = (
+                    sa.update(mod.Message)
+                    .where(mod.Message.fk_remote_pk == remote.pk, 
mod.Message.type != 3)
+                    .values(type=3, resource=remote.jid.resource)
+                )
+                s.execute(stmt)
+            s.commit()
+
+        self._execute_multiple(["PRAGMA user_version=15"])
+
     def _get_account_pks(self, conn: sa.Connection) -> list[int]:
         account_pks: list[int] = []
         for account in app.settings.get_accounts():


=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -69,7 +69,7 @@
 from gajim.common.util.datetime import utc_now
 from gajim.common.util.text import get_random_string
 
-CURRENT_USER_VERSION = 14
+CURRENT_USER_VERSION = 15
 
 
 log = logging.getLogger("gajim.c.storage.archive")



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/5a83b0b84112bee04143f042f1643ba1f6f36385

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/5a83b0b84112bee04143f042f1643ba1f6f36385
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to