Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migration #949

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +21 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old version, this was executed when updating from 1 to 2, so I think it will work now.
https://github.com/fluttercommunity/flutter_downloader/blob/v1.6.1/android/src/main/java/vn/hunghd/flutterdownloader/TaskDbHelper.java#L59-L60

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bowyer-app can you write some comments on your code explaining the change

}

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