Skip to content

Commit

Permalink
Fix failing upgrade from old version (older then db version 145): the…
Browse files Browse the repository at this point in the history
…n attribute is already configured on current enum values

We forgot to add the condition on minimum oldVersion
We now additionally insert with CONFLICT_IGNORE
  • Loading branch information
mtotschnig committed Aug 28, 2024
1 parent 24e5587 commit 9c1cc13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ abstract class BaseTransactionDatabase(
}

fun SupportSQLiteDatabase.upgradeTo164() {
insert("attributes", ContentValues().apply {
safeInsert("attributes", ContentValues().apply {
put("attribute_name", BankingAttribute.BLZ.name)
put("context", BankingAttribute.BLZ.context)
})
Expand All @@ -922,11 +922,11 @@ abstract class BaseTransactionDatabase(
}

fun SupportSQLiteDatabase.upgradeTo167() {
insert("attributes", ContentValues().apply {
safeInsert("attributes", ContentValues().apply {
put("attribute_name", BankingAttribute.NAME.name)
put("context", BankingAttribute.NAME.context)
})
insert("attributes", ContentValues().apply {
safeInsert("attributes", ContentValues().apply {
put("attribute_name", BankingAttribute.BIC.name)
put("context", BankingAttribute.BIC.context)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ fun SupportSQLiteDatabase.update(
fun SupportSQLiteDatabase.insert(table: String, values: ContentValues): Long =
insert(table, SQLiteDatabase.CONFLICT_NONE, values)

/**
* insert where conflicts are ignored instead of raising exception
*/
fun SupportSQLiteDatabase.safeInsert(table: String, values: ContentValues): Long =
insert(table, SQLiteDatabase.CONFLICT_IGNORE, values)


fun SupportSQLiteDatabase.query(
table: String,
columns: Array<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ public void onUpgrade(@NonNull SupportSQLiteDatabase db, int oldVersion, int new
db.execSQL("UPDATE banks set version = 1");
}

if (oldVersion < 167) {
if (oldVersion >= 145 && oldVersion < 167) {
upgradeTo167(db);
}

Expand Down

0 comments on commit 9c1cc13

Please sign in to comment.