Run database migrations automatically on startup

Instead of using sequelize-cli and ensure migrations by shellscript,
this patch automates database migrations properly to the umzug library.
The sequelize CLI becomes a dev dependencies as it's still useful for
generating migrations.

This should eliminate the need for crude generating of database config
files and alike. Instead we utilize the pre-configured sequelize
connection that CodiMD will use anyway.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
Sheogorath 2020-06-02 13:48:38 +02:00
parent 2c3522992b
commit 6c1ca5bd8d
No known key found for this signature in database
GPG key ID: C9B1C80737B9CE18
19 changed files with 70 additions and 35 deletions

View file

@ -24,7 +24,7 @@ import { config } from './config'
import { addNonceToLocals, computeDirectives } from './csp'
import { errors } from './errors'
import { logger } from './logger'
import { Revision, sequelize } from './models'
import { Revision, sequelize, runMigrations } from './models'
import { realtime, State } from './realtime'
import { handleTermSignals } from './utils/functions'
import { AuthRouter, BaseRouter, HistoryRouter, ImageRouter, NoteRouter, StatusRouter, UserRouter } from './web/'
@ -289,7 +289,8 @@ function startListen (): void {
}
// sync db then start listen
sequelize.authenticate().then(function () {
sequelize.authenticate().then(async function () {
await runMigrations()
sessionStore.sync()
// check if realtime is ready
if (realtime.isReady()) {