From ed708d62a677fc75311220739389dfe6b869cfad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 4 Mar 2017 10:40:09 +0100 Subject: Server: fix migrations with an empty Applications table --- server/initializers/migrator.js | 12 ++++++++++++ server/models/application.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/initializers/migrator.js b/server/initializers/migrator.js index 8c67903ad..0f25a23d1 100644 --- a/server/initializers/migrator.js +++ b/server/initializers/migrator.js @@ -32,6 +32,18 @@ function migrate (finalCallback) { db.Application.loadMigrationVersion(callback) }, + function createMigrationRowIfNotExists (actualVersion, callback) { + if (actualVersion === null) { + db.Application.create({ + migrationVersion: 0 + }, function (err) { + return callabck(err, 0) + }) + } + + return callback(null, actualVersion) + }, + function abortMigrationIfNotNeeded (actualVersion, callback) { // No need migrations if (actualVersion >= constants.LAST_MIGRATION_VERSION) return finalCallback(null) diff --git a/server/models/application.js b/server/models/application.js index 46dcfde33..64e1a0540 100644 --- a/server/models/application.js +++ b/server/models/application.js @@ -31,7 +31,7 @@ function loadMigrationVersion (callback) { } return this.findOne(query).asCallback(function (err, data) { - const version = data ? data.migrationVersion : 0 + const version = data ? data.migrationVersion : null return callback(err, version) }) -- cgit v1.2.3