From 0047d5b728a1e6e73cc6b575fb4289ab4cfee26f Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Sun, 29 Nov 2020 22:33:38 +0530 Subject: [PATCH] fix: set correct exit code for the commands --- commands/DbSeed.ts | 11 +++++++++++ commands/Migration/Base.ts | 1 + commands/Migration/Rollback.ts | 1 + commands/Migration/Run.ts | 1 + commands/Migration/Status.ts | 1 + 5 files changed, 15 insertions(+) diff --git a/commands/DbSeed.ts b/commands/DbSeed.ts index e0dc86ae..20804731 100644 --- a/commands/DbSeed.ts +++ b/commands/DbSeed.ts @@ -15,6 +15,11 @@ export default class DbSeed extends BaseCommand { public static commandName = 'db:seed' public static description = 'Execute database seeder files' + /** + * Track if one or more seeders have failed + */ + private hasError: boolean = false + /** * Choose a custom pre-defined connection. Otherwise, we use the * default connection @@ -149,12 +154,18 @@ export default class DbSeed extends BaseCommand { status: 'failed', error: new Error('Invalid file path. Pass relative path from the application root'), }) + this.hasError = true } else { const response = await runner.run(sourceFile) + if (response.status === 'failed') { + this.hasError = true + } + this.printLogMessage(response) } } + this.exitCode = this.hasError ? 1 : 0 await db.manager.closeAll(true) } } diff --git a/commands/Migration/Base.ts b/commands/Migration/Base.ts index 9dbc8d91..2b9d9963 100644 --- a/commands/Migration/Base.ts +++ b/commands/Migration/Base.ts @@ -162,6 +162,7 @@ export default abstract class MigrationsBase extends BaseCommand { break case 'error': this.logger.fatal(migrator.error!) + this.exitCode = 1 break } } diff --git a/commands/Migration/Rollback.ts b/commands/Migration/Rollback.ts index e5a04dbf..97ce21bf 100644 --- a/commands/Migration/Rollback.ts +++ b/commands/Migration/Rollback.ts @@ -78,6 +78,7 @@ export default class Migrate extends MigrationsBase { */ if (!connection) { this.printNotAValidConnection(this.connection) + this.exitCode = 1 return } diff --git a/commands/Migration/Run.ts b/commands/Migration/Run.ts index 81b9e1f2..44591cf3 100644 --- a/commands/Migration/Run.ts +++ b/commands/Migration/Run.ts @@ -69,6 +69,7 @@ export default class Migrate extends MigrationsBase { */ if (!connection) { this.printNotAValidConnection(this.connection) + this.exitCode = 1 return } diff --git a/commands/Migration/Status.ts b/commands/Migration/Status.ts index 816eaea7..5dbb1795 100644 --- a/commands/Migration/Status.ts +++ b/commands/Migration/Status.ts @@ -62,6 +62,7 @@ export default class Status extends MigrationsBase { */ if (!connection) { this.printNotAValidConnection(this.connection) + this.exitCode = 1 return }