From ee8c507faba3a6c5d05916b7c973611ac72cfc8a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 27 Jun 2025 13:15:39 +0200 Subject: [PATCH] clear tables during migration (see comment) Foreign key constraints are not active during migration. At least db.execSQL("PRAGMA foreign_keys=ON;") etc did not help. Because of this it is not enough to just clear the Conversations table (to have cascade deletion in other tables), but all related tables have to be cleared with SQL statement as well. Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/data/source/local/Migrations.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/data/source/local/Migrations.kt b/app/src/main/java/com/nextcloud/talk/data/source/local/Migrations.kt index 2b99d70da..21d7b0b42 100644 --- a/app/src/main/java/com/nextcloud/talk/data/source/local/Migrations.kt +++ b/app/src/main/java/com/nextcloud/talk/data/source/local/Migrations.kt @@ -343,8 +343,6 @@ object Migrations { fun migrateToMessageThreads(db: SupportSQLiteDatabase) { try { - // db.execSQL("PRAGMA foreign_keys=ON;") - db.execSQL( "ALTER TABLE ChatBlocks " + "ADD COLUMN threadId INTEGER DEFAULT NULL;" @@ -365,9 +363,20 @@ object Migrations { "ADD COLUMN threadId INTEGER DEFAULT NULL;" ) + // Foreign key constraints are not active during migration. + // At least db.execSQL("PRAGMA foreign_keys=ON;") etc did not help. + // Because of this it is not enough to just clear the Conversations table (to have cascade deletion in + // other tables), but all related tables have to be cleared with SQL statement as well. + db.execSQL( "DELETE FROM Conversations" ) + db.execSQL( + "DELETE FROM ChatMessages" + ) + db.execSQL( + "DELETE FROM ChatBlocks" + ) } catch (e: SQLException) { Log.i("Migrations", "Something went wrong when migrating to messageThreads", e) }