feat: auto-run MongoDB migrations at boot in MongodbProvider
This commit is contained in:
1 parent
7ac4e018a2
commit
e645157970
1 file changed
+14
@@ -40,6 +40,20 @@ export default class MongodbProvider {
|
||||
dbInstance = db
|
||||
this.app.container.bindValue('mongodb', db)
|
||||
|
||||
// Run pending MongoDB migrations automatically at boot
|
||||
const { MigratorRunner } = await import('../database/mongo_migrator.js')
|
||||
const migrationsPath = this.app.makePath('database/mongo_migrations')
|
||||
const migrator = new MigratorRunner(db, migrationsPath)
|
||||
const ran = await migrator.run().catch((err: Error) => {
|
||||
console.warn(`[MongoMigrator] Failed to run migrations: ${err.message}`)
|
||||
return [] as string[]
|
||||
})
|
||||
if (ran.length > 0) {
|
||||
console.info(`[MongoMigrator] Applied ${ran.length} migration(s): ${ran.join(', ')}`)
|
||||
} else {
|
||||
console.info('[MongoMigrator] Database is up to date.')
|
||||
}
|
||||
|
||||
// Verify cwmp_exchanges indexes after boot
|
||||
const { verifyIndexesAtStartup } = await import('#services/exchange_index_checker')
|
||||
await verifyIndexesAtStartup(db, {
|
||||
|
||||
Reference in new issue
Block a user