Drop index on key metadata table
Key metadata can exist without a keyring in the table, so we don't lose it on reinsertion. Also, don't use transactions inside database upgrade tasks. The entire update is wrapped in a transaction, and we don't want to break this!
This commit is contained in:
parent
865b35d79f
commit
6cb773c45d
|
@ -48,7 +48,7 @@ import timber.log.Timber;
|
||||||
*/
|
*/
|
||||||
public class KeychainDatabase {
|
public class KeychainDatabase {
|
||||||
private static final String DATABASE_NAME = "openkeychain.db";
|
private static final String DATABASE_NAME = "openkeychain.db";
|
||||||
private static final int DATABASE_VERSION = 33;
|
private static final int DATABASE_VERSION = 34;
|
||||||
private final SupportSQLiteOpenHelper supportSQLiteOpenHelper;
|
private final SupportSQLiteOpenHelper supportSQLiteOpenHelper;
|
||||||
|
|
||||||
private static KeychainDatabase sInstance;
|
private static KeychainDatabase sInstance;
|
||||||
|
@ -282,8 +282,6 @@ public class KeychainDatabase {
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
||||||
case 24: {
|
case 24: {
|
||||||
try {
|
|
||||||
db.beginTransaction();
|
|
||||||
db.execSQL("ALTER TABLE api_autocrypt_peers RENAME TO tmp");
|
db.execSQL("ALTER TABLE api_autocrypt_peers RENAME TO tmp");
|
||||||
db.execSQL("CREATE TABLE api_autocrypt_peers ("
|
db.execSQL("CREATE TABLE api_autocrypt_peers ("
|
||||||
+ "package_name TEXT NOT NULL, "
|
+ "package_name TEXT NOT NULL, "
|
||||||
|
@ -316,10 +314,6 @@ public class KeychainDatabase {
|
||||||
"SELECT package_name, identifier, last_updated, last_seen_key, master_key_id, 1 " +
|
"SELECT package_name, identifier, last_updated, last_seen_key, master_key_id, 1 " +
|
||||||
"FROM tmp WHERE state = 4"); // from Autocrypt 0.X, state = "mutual"
|
"FROM tmp WHERE state = 4"); // from Autocrypt 0.X, state = "mutual"
|
||||||
db.execSQL("DROP TABLE tmp");
|
db.execSQL("DROP TABLE tmp");
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
db.execSQL("CREATE INDEX IF NOT EXISTS uids_by_email ON user_packets (email);");
|
db.execSQL("CREATE INDEX IF NOT EXISTS uids_by_email ON user_packets (email);");
|
||||||
db.execSQL("DROP INDEX keys_by_rank");
|
db.execSQL("DROP INDEX keys_by_rank");
|
||||||
|
@ -355,29 +349,22 @@ public class KeychainDatabase {
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
recreateUnifiedKeyView(db);
|
recreateUnifiedKeyView(db);
|
||||||
|
|
||||||
|
case 33:
|
||||||
|
dropKeyMetadataForeignKey(db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSubkeyValidFromField(SupportSQLiteDatabase db) {
|
private void addSubkeyValidFromField(SupportSQLiteDatabase db) {
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
|
||||||
db.execSQL("ALTER TABLE keys ADD COLUMN validFrom INTEGER NOT NULL DEFAULT 0;");
|
db.execSQL("ALTER TABLE keys ADD COLUMN validFrom INTEGER NOT NULL DEFAULT 0;");
|
||||||
db.execSQL("UPDATE keys SET validFrom = creation");
|
db.execSQL("UPDATE keys SET validFrom = creation");
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} catch (SQLiteException e) {
|
} catch (SQLiteException e) {
|
||||||
// column probably already existed, nvm this
|
// column probably already existed, nvm this
|
||||||
if (!Constants.DEBUG) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recreateUnifiedKeyView(SupportSQLiteDatabase db) {
|
private void recreateUnifiedKeyView(SupportSQLiteDatabase db) {
|
||||||
try {
|
|
||||||
db.beginTransaction();
|
|
||||||
|
|
||||||
// noinspection deprecation
|
// noinspection deprecation
|
||||||
db.execSQL("DROP VIEW IF EXISTS " + KeysModel.UNIFIEDKEYVIEW_VIEW_NAME);
|
db.execSQL("DROP VIEW IF EXISTS " + KeysModel.UNIFIEDKEYVIEW_VIEW_NAME);
|
||||||
db.execSQL(KeysModel.UNIFIEDKEYVIEW);
|
db.execSQL(KeysModel.UNIFIEDKEYVIEW);
|
||||||
|
@ -390,11 +377,15 @@ public class KeychainDatabase {
|
||||||
// noinspection deprecation
|
// noinspection deprecation
|
||||||
db.execSQL("DROP VIEW IF EXISTS " + UserPacketsModel.UIDSTATUS_VIEW_NAME);
|
db.execSQL("DROP VIEW IF EXISTS " + UserPacketsModel.UIDSTATUS_VIEW_NAME);
|
||||||
db.execSQL(UserPacketsModel.UIDSTATUS);
|
db.execSQL(UserPacketsModel.UIDSTATUS);
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void dropKeyMetadataForeignKey(SupportSQLiteDatabase db) {
|
||||||
|
// noinspection deprecation
|
||||||
|
db.execSQL("ALTER TABLE " + KeyMetadataModel.TABLE_NAME + " RENAME TO metadata_tmp");
|
||||||
|
db.execSQL(KeyMetadataModel.CREATE_TABLE);
|
||||||
|
// noinspection deprecation
|
||||||
|
db.execSQL("INSERT INTO " + KeyMetadataModel.TABLE_NAME + " SELECT * FROM metadata_tmp");
|
||||||
|
db.execSQL("DROP TABLE metadata_tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void migrateSecretKeysFromDbToLocalStorage(SupportSQLiteDatabase db, Context context) throws IOException {
|
private void migrateSecretKeysFromDbToLocalStorage(SupportSQLiteDatabase db, Context context) throws IOException {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
-- NOTE: This table's data is NOT bound to keyrings_public! There may be
|
||||||
|
-- entries here that no longer have a corresponding key in the database!
|
||||||
CREATE TABLE IF NOT EXISTS key_metadata (
|
CREATE TABLE IF NOT EXISTS key_metadata (
|
||||||
master_key_id INTEGER PRIMARY KEY,
|
master_key_id INTEGER PRIMARY KEY,
|
||||||
last_updated INTEGER AS Date,
|
last_updated INTEGER AS Date,
|
||||||
seen_on_keyservers INTEGER AS Boolean,
|
seen_on_keyservers INTEGER AS Boolean
|
||||||
FOREIGN KEY(master_key_id) REFERENCES keyrings_public(master_key_id) ON DELETE CASCADE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
selectByMasterKeyId:
|
selectByMasterKeyId:
|
||||||
|
|
Loading…
Reference in a new issue