feat: auto-run MongoDB migrations at boot in MongodbProvider
Build & Deploy / build (push) Successful in 34s
Build & Deploy / docker (push) Successful in 1m8s
Build & Deploy / deploy (push) Successful in 24s

This commit is contained in:
L HEREEC Kevin INNOV/PTFM committed 2026-07-13 15:03:19 +02:00
1 parent 7ac4e018a2
commit e645157970
1 file changed
+14
+14
View File
@@ -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, {