Allow attachment migration run on higher database version

This commit is contained in:
Daniel Gasienica 2018-03-28 14:45:07 -04:00
parent 921c3dba7c
commit efe3cd67fc
3 changed files with 18 additions and 6 deletions

View file

@ -91,7 +91,7 @@
await MessageDataMigrator.processAll({
Backbone,
databaseName: database.name,
databaseVersion: database.version,
minDatabaseVersion: database.version,
upgradeMessageSchema,
});

View file

@ -77,7 +77,7 @@ exports.processNext = async ({
exports.processAll = async ({
Backbone,
databaseName,
databaseVersion,
minDatabaseVersion,
upgradeMessageSchema,
} = {}) => {
if (!isObject(Backbone)) {
@ -88,15 +88,27 @@ exports.processAll = async ({
throw new TypeError('"databaseName" must be a string');
}
if (!isNumber(databaseVersion)) {
throw new TypeError('"databaseVersion" must be a number');
if (!isNumber(minDatabaseVersion)) {
throw new TypeError('"minDatabaseVersion" must be a number');
}
if (!isFunction(upgradeMessageSchema)) {
throw new TypeError('"upgradeMessageSchema" is required');
}
const connection = await database.open(databaseName, databaseVersion);
const connection = await database.open(databaseName);
const databaseVersion = connection.version;
const isValidDatabaseVersion = databaseVersion >= minDatabaseVersion;
console.log('Database status', {
databaseVersion,
isValidDatabaseVersion,
minDatabaseVersion,
});
if (!isValidDatabaseVersion) {
throw new Error(`Expected database version (${databaseVersion})` +
` to be at least ${minDatabaseVersion}`);
}
const isComplete = await settings.isAttachmentMigrationComplete(connection);
console.log('Attachment migration status:', isComplete ? 'complete' : 'incomplete');
if (isComplete) {

View file

@ -32,7 +32,7 @@ exports.runMigrations = async ({ Backbone, database } = {}) => {
const databaseVersion = await db.getVersion(database.id);
const isAlreadyUpgraded = databaseVersion >= lastMigrationVersion;
console.log('Database state', {
console.log('Database status', {
firstMigrationVersion,
lastMigrationVersion,
databaseVersion,