Allow attachment migration run on higher database version
This commit is contained in:
parent
921c3dba7c
commit
efe3cd67fc
3 changed files with 18 additions and 6 deletions
|
@ -91,7 +91,7 @@
|
||||||
await MessageDataMigrator.processAll({
|
await MessageDataMigrator.processAll({
|
||||||
Backbone,
|
Backbone,
|
||||||
databaseName: database.name,
|
databaseName: database.name,
|
||||||
databaseVersion: database.version,
|
minDatabaseVersion: database.version,
|
||||||
upgradeMessageSchema,
|
upgradeMessageSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ exports.processNext = async ({
|
||||||
exports.processAll = async ({
|
exports.processAll = async ({
|
||||||
Backbone,
|
Backbone,
|
||||||
databaseName,
|
databaseName,
|
||||||
databaseVersion,
|
minDatabaseVersion,
|
||||||
upgradeMessageSchema,
|
upgradeMessageSchema,
|
||||||
} = {}) => {
|
} = {}) => {
|
||||||
if (!isObject(Backbone)) {
|
if (!isObject(Backbone)) {
|
||||||
|
@ -88,15 +88,27 @@ exports.processAll = async ({
|
||||||
throw new TypeError('"databaseName" must be a string');
|
throw new TypeError('"databaseName" must be a string');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNumber(databaseVersion)) {
|
if (!isNumber(minDatabaseVersion)) {
|
||||||
throw new TypeError('"databaseVersion" must be a number');
|
throw new TypeError('"minDatabaseVersion" must be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFunction(upgradeMessageSchema)) {
|
if (!isFunction(upgradeMessageSchema)) {
|
||||||
throw new TypeError('"upgradeMessageSchema" is required');
|
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);
|
const isComplete = await settings.isAttachmentMigrationComplete(connection);
|
||||||
console.log('Attachment migration status:', isComplete ? 'complete' : 'incomplete');
|
console.log('Attachment migration status:', isComplete ? 'complete' : 'incomplete');
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ exports.runMigrations = async ({ Backbone, database } = {}) => {
|
||||||
const databaseVersion = await db.getVersion(database.id);
|
const databaseVersion = await db.getVersion(database.id);
|
||||||
const isAlreadyUpgraded = databaseVersion >= lastMigrationVersion;
|
const isAlreadyUpgraded = databaseVersion >= lastMigrationVersion;
|
||||||
|
|
||||||
console.log('Database state', {
|
console.log('Database status', {
|
||||||
firstMigrationVersion,
|
firstMigrationVersion,
|
||||||
lastMigrationVersion,
|
lastMigrationVersion,
|
||||||
databaseVersion,
|
databaseVersion,
|
||||||
|
|
Loading…
Reference in a new issue