Blow up the Settings Search Index database if there is a Database downgrade detected
- use the onDowngrade(...) callback for blowing away the Search Index database and recompute the Index. Change-Id: I137b22e710dd3205063cf8ce239105b2f1c5278b
This commit is contained in:
@@ -133,17 +133,44 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
Log.i(TAG, "Bootstrapped database");
|
Log.i(TAG, "Bootstrapped database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(SQLiteDatabase db) {
|
||||||
|
super.onOpen(db);
|
||||||
|
|
||||||
|
Log.i(TAG, "Using schema version: " + db.getVersion());
|
||||||
|
|
||||||
|
if (!Build.VERSION.INCREMENTAL.equals(getBuildVersion(db))) {
|
||||||
|
Log.w(TAG, "Index needs to be rebuilt as build-version is not the same");
|
||||||
|
// We need to drop the tables and recreate them
|
||||||
|
reconstruct(db);
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Index is fine");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
if (oldVersion == 100 || oldVersion == 101 || oldVersion == 102 || oldVersion == 103) {
|
if (oldVersion == 100 || oldVersion == 101 || oldVersion == 102 || oldVersion == 103) {
|
||||||
Log.w(TAG, "Detected schema version 100, 101, 102 or 103. " +
|
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
||||||
"Index needs to be rebuilt for schema version 104");
|
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
||||||
// We need to drop the tables and recreate them
|
// We need to drop the tables and recreate them
|
||||||
dropTables(db);
|
reconstruct(db);
|
||||||
bootstrapDB(db);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
||||||
|
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
||||||
|
// We need to drop the tables and recreate them
|
||||||
|
reconstruct(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reconstruct(SQLiteDatabase db) {
|
||||||
|
dropTables(db);
|
||||||
|
bootstrapDB(db);
|
||||||
|
}
|
||||||
|
|
||||||
private String getBuildVersion(SQLiteDatabase db) {
|
private String getBuildVersion(SQLiteDatabase db) {
|
||||||
String version = null;
|
String version = null;
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
@@ -168,20 +195,4 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
|
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
|
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOpen(SQLiteDatabase db) {
|
|
||||||
super.onOpen(db);
|
|
||||||
|
|
||||||
Log.i(TAG, "Using schema version: " + db.getVersion());
|
|
||||||
|
|
||||||
if (!Build.VERSION.INCREMENTAL.equals(getBuildVersion(db))) {
|
|
||||||
Log.w(TAG, "Index needs to be rebuilt as build-version is not the same");
|
|
||||||
// We need to drop the tables and recreate them
|
|
||||||
dropTables(db);
|
|
||||||
bootstrapDB(db);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Index is fine");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user