From 0db862f3c9318f3e214d6b09604760a9844dcfd5 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sat, 27 Feb 2021 21:33:05 +0100 Subject: Run database migrations automatically on startup This commit removes the need for separate migrations with the sequelize-cli by running them with umzug on application startup. This is a port of #384 Co-authored-by: Sheogorath Signed-off-by: David Mehren --- app.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index ae332d98..ce37032b 100644 --- a/app.js +++ b/app.js @@ -264,16 +264,19 @@ function startListen () { } // sync db then start listen -models.sequelize.sync().then(function () { - // check if realtime is ready - if (realtime.isReady()) { - models.Revision.checkAllNotesRevision(function (err, notes) { - if (err) throw new Error(err) - if (!notes || notes.length <= 0) return startListen() - }) - } else { - throw new Error('server still not ready after db synced') - } +models.sequelize.authenticate().then(function () { + models.runMigrations().then(() => { + sessionStore.sync() + // check if realtime is ready + if (realtime.isReady()) { + models.Revision.checkAllNotesRevision(function (err, notes) { + if (err) throw new Error(err) + if (!notes || notes.length <= 0) return startListen() + }) + } else { + throw new Error('server still not ready after db synced') + } + }) }) // log uncaught exception -- cgit v1.2.3