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 <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-06-27 13:15:39 +02:00
parent dfb0a10c70
commit ee8c507fab
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -343,8 +343,6 @@ object Migrations {
fun migrateToMessageThreads(db: SupportSQLiteDatabase) { fun migrateToMessageThreads(db: SupportSQLiteDatabase) {
try { try {
// db.execSQL("PRAGMA foreign_keys=ON;")
db.execSQL( db.execSQL(
"ALTER TABLE ChatBlocks " + "ALTER TABLE ChatBlocks " +
"ADD COLUMN threadId INTEGER DEFAULT NULL;" "ADD COLUMN threadId INTEGER DEFAULT NULL;"
@ -365,9 +363,20 @@ object Migrations {
"ADD COLUMN threadId INTEGER DEFAULT NULL;" "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( db.execSQL(
"DELETE FROM Conversations" "DELETE FROM Conversations"
) )
db.execSQL(
"DELETE FROM ChatMessages"
)
db.execSQL(
"DELETE FROM ChatBlocks"
)
} catch (e: SQLException) { } catch (e: SQLException) {
Log.i("Migrations", "Something went wrong when migrating to messageThreads", e) Log.i("Migrations", "Something went wrong when migrating to messageThreads", e)
} }