mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Handle possible erroneous DB migrations for BookmarksLocationDao (#4657)
This commit is contained in:
parent
ade568008d
commit
25b9244066
2 changed files with 20 additions and 31 deletions
|
|
@ -274,38 +274,27 @@ 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");
|
||||||
|
addColumn(db, "location_exists", "STRING");
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (from >= 12) {
|
|
||||||
|
private static void addColumn(final SQLiteDatabase db, final String columnName,
|
||||||
|
final String type){
|
||||||
try {
|
try {
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;");
|
String.format("ALTER TABLE bookmarksLocations ADD COLUMN %s %s;", columnName,
|
||||||
} catch (SQLiteException exception) {
|
type));
|
||||||
|
} catch (final SQLiteException exception) {
|
||||||
Timber.e(exception);
|
Timber.e(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (from >= 13){
|
|
||||||
try {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue