Skip to content

Commit

Permalink
fix(logging): database name where we execute migrations added
Browse files Browse the repository at this point in the history
  • Loading branch information
Stradivario committed Apr 23, 2024
1 parent 1b6c230 commit 2488b83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/injection.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface BundlerConfig {

export interface Config {
database: {
_database_name?: string;
_connection_cache?: MongoClient;
connect?(): Promise<MongoClient>;
};
Expand Down
11 changes: 10 additions & 1 deletion src/migrations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 4 additions & 0 deletions src/services/generic-runner/generic-runner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
Expand Down

0 comments on commit 2488b83

Please sign in to comment.