Skip to content

Commit

Permalink
Merge pull request #3436 from FlowFuse/3426-scalable-db-strategy
Browse files Browse the repository at this point in the history
Generate database structure via migration
  • Loading branch information
knolleary committed Feb 7, 2024
2 parents 215d7a2 + 7a43a52 commit 8b76c12
Show file tree
Hide file tree
Showing 8 changed files with 1,205 additions and 38 deletions.
10 changes: 2 additions & 8 deletions forge/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = fp(async function (app, _opts) {
controllers,
utils
}

app.decorate('db', db)

app.addHook('onClose', async (_) => {
Expand All @@ -76,15 +77,8 @@ module.exports = fp(async function (app, _opts) {
await sequelize.authenticate()

await migrations.init(app)
await migrations.applyPendingMigrations()

if (migrations.hasPendingMigrations()) {
app.log.info('Database has pending migrations')
if (!app.config.db.migrations || app.config.db.migrations.auto !== false) {
await migrations.applyPendingMigrations()
} else if (!app.config.db.migrations || !app.config.db.migrations.skipCheck) {
throw new Error('Unapplied migrations')
}
}
await models.init(app)
await views.init(app)
await controllers.init(app)
Expand Down
Loading

0 comments on commit 8b76c12

Please sign in to comment.