diff --git a/src/injection.tokens.ts b/src/injection.tokens.ts index 7b66168..f8b1257 100644 --- a/src/injection.tokens.ts +++ b/src/injection.tokens.ts @@ -36,6 +36,7 @@ export interface BundlerConfig { export interface Config { database: { + _database_name?: string; _connection_cache?: MongoClient; connect?(): Promise; }; diff --git a/src/migrations.module.ts b/src/migrations.module.ts index 0006de2..e3c866b 100644 --- a/src/migrations.module.ts +++ b/src/migrations.module.ts @@ -68,11 +68,17 @@ export class MigrationsModule { }, { provide: 'start', - deps: [CommandInjector, GenericRunner, ConfigService], + deps: [ + CommandInjector, + GenericRunner, + ConfigService, + MigrationService, + ], useFactory: async ( { command, argv }: { command: Tasks; argv: unknown[] }, runner: GenericRunner, configService: ConfigService, + migrationService: MigrationService, ) => { try { let settings; @@ -141,6 +147,9 @@ export class MigrationsModule { await ensureDir(configService.config.logger.folder); await ensureDir(configService.config.migrationsDir); let hasCrashed: boolean; + + await migrationService.connect(); + if (command === 'create') { hasCrashed = await runner.run('create', { name: argv[1], diff --git a/src/services/generic-runner/generic-runner.service.ts b/src/services/generic-runner/generic-runner.service.ts index 1652391..e1d3709 100644 --- a/src/services/generic-runner/generic-runner.service.ts +++ b/src/services/generic-runner/generic-runner.service.ts @@ -118,11 +118,15 @@ export class GenericRunner { private async logEnvironment(taskName: string) { const { + database: { _connection_cache }, migrationsDir, logger: { folder }, changelogCollectionName, } = this.configService.config; console.log(` + \n🖥️ ${chalk.bold('Database:')} ${chalk.blue.bold( + _connection_cache.db().databaseName, + )} \n💿 ${chalk.bold('DBCollection:')} ${chalk.blue.bold( changelogCollectionName, )}