Don't reset "transient" tables from now on.

Instead, use:

if (oldVersion < ... && !columnExists(...))
	db.execSQL("ALTER TABLE ...")

to add/modify columns as required.
This commit is contained in:
Peter Serwylo 2014-03-19 06:22:07 +11:00
parent 53a10aa44f
commit fa8052611e

View File

@ -87,7 +87,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ "iconUrl text, " + "iconUrl text, "
+ "primary key(id));"; + "primary key(id));";
private static final int DB_VERSION = 41; private static final int DB_VERSION = 42;
private Context context; private Context context;
@ -231,12 +231,12 @@ public class DBHelper extends SQLiteOpenHelper {
Log.i("FDroid", "Upgrading database from v" + oldVersion + " v" Log.i("FDroid", "Upgrading database from v" + oldVersion + " v"
+ newVersion); + newVersion);
migradeRepoTable(db, oldVersion); migrateRepoTable(db, oldVersion);
// The other tables are transient and can just be reset. Do this after // The other tables are transient and can just be reset. Do this after
// the repo table changes though, because it also clears the lastetag // the repo table changes though, because it also clears the lastetag
// fields which didn't always exist. // fields which didn't always exist.
resetTransient(db); resetTransient(db, oldVersion);
addNameAndDescriptionToRepo(db, oldVersion); addNameAndDescriptionToRepo(db, oldVersion);
addFingerprintToRepo(db, oldVersion); addFingerprintToRepo(db, oldVersion);
@ -251,7 +251,7 @@ public class DBHelper extends SQLiteOpenHelper {
* Migrate repo list to new structure. (No way to change primary * Migrate repo list to new structure. (No way to change primary
* key in sqlite - table must be recreated). * key in sqlite - table must be recreated).
*/ */
private void migradeRepoTable(SQLiteDatabase db, int oldVersion) { private void migrateRepoTable(SQLiteDatabase db, int oldVersion) {
if (oldVersion < 20) { if (oldVersion < 20) {
List<Repo> oldrepos = new ArrayList<Repo>(); List<Repo> oldrepos = new ArrayList<Repo>();
Cursor c = db.query(TABLE_REPO, Cursor c = db.query(TABLE_REPO,
@ -355,13 +355,20 @@ public class DBHelper extends SQLiteOpenHelper {
} }
} }
private void resetTransient(SQLiteDatabase db) { private void resetTransient(SQLiteDatabase db, int oldVersion) {
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit() // Before version 42, only transient info was stored in here. As of some time
.putBoolean("triedEmptyUpdate", false).commit(); // just before 42 (F-Droid 0.60ish) it now has "ignore this version" info which
db.execSQL("drop table " + TABLE_APP); // was is specified by the user. We don't want to weely-neely nuke that data.
db.execSQL("drop table " + TABLE_APK); // and the new way to deal with changes to the table structure is to add a
db.execSQL("update " + TABLE_REPO + " set lastetag = NULL"); // if (oldVersion < x && !columnExists(...) and then alter the table as required.
createAppApk(db); if (oldVersion < 42) {
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit()
.putBoolean("triedEmptyUpdate", false).commit();
db.execSQL("drop table " + TABLE_APP);
db.execSQL("drop table " + TABLE_APK);
db.execSQL("update " + TABLE_REPO + " set lastetag = NULL");
createAppApk(db);
}
} }
private static void createAppApk(SQLiteDatabase db) { private static void createAppApk(SQLiteDatabase db) {