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 477bd7676f
commit 7d6cdb9e0d
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) {
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)
}