Skip to content

Commit

Permalink
Fix migration (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowyer-app authored Oct 21, 2024
1 parent 81aaf55 commit a7bc2ab
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,31 @@ class TaskDbHelper private constructor(context: Context) :
}

override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
if (newVersion == 4) {
db.execSQL("ALTER TABLE ${TaskEntry.TABLE_NAME} ADD COLUMN ${TaskEntry.COLUMN_ALLOW_CELLULAR} TINYINT DEFAULT 1")
} else if (oldVersion == 2 && newVersion == 3) {
db.execSQL("ALTER TABLE " + TaskEntry.TABLE_NAME + " ADD COLUMN " + TaskEntry.COLUMN_SAVE_IN_PUBLIC_STORAGE + " TINYINT DEFAULT 0")
} else {
db.execSQL(SQL_DELETE_ENTRIES)
onCreate(db)
update1to2(db, oldVersion)
update2to3(db, oldVersion)
update3to4(db, oldVersion)
}

private fun update1to2(db: SQLiteDatabase, oldVersion: Int) {
if (oldVersion > 1) {
return
}
db.execSQL(SQL_DELETE_ENTRIES)
onCreate(db)
}

private fun update2to3(db: SQLiteDatabase, oldVersion: Int) {
if (oldVersion > 2) {
return
}
db.execSQL("ALTER TABLE " + TaskEntry.TABLE_NAME + " ADD COLUMN " + TaskEntry.COLUMN_SAVE_IN_PUBLIC_STORAGE + " TINYINT DEFAULT 0")
}

private fun update3to4(db: SQLiteDatabase, oldVersion: Int) {
if (oldVersion > 3) {
return
}
db.execSQL("ALTER TABLE ${TaskEntry.TABLE_NAME} ADD COLUMN ${TaskEntry.COLUMN_ALLOW_CELLULAR} TINYINT DEFAULT 1")
}

override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
Expand Down

0 comments on commit a7bc2ab

Please sign in to comment.