Handle possible erroneous DB migrations for BookmarksLocationDao (#4657)

This commit is contained in:
Ashish 2021-10-05 00:47:28 +05:30 committed by GitHub
parent ade568008d
commit 25b9244066
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 31 deletions

View file

@ -274,37 +274,26 @@ public class BookmarkLocationsDao {
onUpdate(db, from, to); onUpdate(db, from, to);
return; return;
} }
if (from == 10) {
//This is safe, and can be called clean, as we/I do not remember the appropriate version for this //We've been seeing many cases where one of these seem to have missed to added and its
//We are anyways switching to room, these things won't be necessary then // hard to find the exact version knowing which version the user is going to upgrade from,
try { //before until this version (18), we want to make sure that these column do exist
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_pic STRING;"); if (from <= 17) {
}catch (SQLiteException exception){ addColumn(db, "location_pic", "STRING");
Timber.e(exception);// addColumn(db, "location_destroyed", "STRING");
} addColumn(db, "location_language", "STRING");
return; addColumn(db, "location_exists", "STRING");
} }
if (from >= 12) { }
try {
db.execSQL( private static void addColumn(final SQLiteDatabase db, final String columnName,
"ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;"); final String type){
} catch (SQLiteException exception) { try {
Timber.e(exception); db.execSQL(
} String.format("ALTER TABLE bookmarksLocations ADD COLUMN %s %s;", columnName,
} type));
if (from >= 13){ } catch (final SQLiteException exception) {
try { Timber.e(exception);
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_language STRING;");
} catch (SQLiteException exception){
Timber.e(exception);
}
}
if (from >= 14){
try {
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_exists STRING;");
} catch (SQLiteException exception){
Timber.e(exception);
}
} }
} }
} }

View file

@ -13,7 +13,7 @@ import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao;
public class DBOpenHelper extends SQLiteOpenHelper { public class DBOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "commons.db"; private static final String DATABASE_NAME = "commons.db";
private static final int DATABASE_VERSION = 17; private static final int DATABASE_VERSION = 18;
public static final String CONTRIBUTIONS_TABLE = "contributions"; public static final String CONTRIBUTIONS_TABLE = "contributions";
private final String DROP_TABLE_STATEMENT="DROP TABLE IF EXISTS %s"; private final String DROP_TABLE_STATEMENT="DROP TABLE IF EXISTS %s";