diff --git a/package.json b/package.json index b297a20..7d867cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/database", - "version": "5.6.0", + "version": "5.7.0", "description": "The Athenna database handler for SQL/NoSQL.", "license": "MIT", "author": "João Lenon ", diff --git a/src/commands/DbFreshCommand.ts b/src/commands/DbFreshCommand.ts index 963c0c6..c8a48e9 100644 --- a/src/commands/DbFreshCommand.ts +++ b/src/commands/DbFreshCommand.ts @@ -36,11 +36,24 @@ export class DbWipeCommand extends BaseCommand { await Artisan.call(`db:wipe --connection ${this.connection}`) console.log() - await Artisan.call(`migration:run --connection ${this.connection}`) + if (this.getConfig('driver') !== 'mongo') { + await Artisan.call(`migration:run --connection ${this.connection}`) + } if (this.withSeeders) { console.log() await Artisan.call(`db:seed --connection ${this.connection}`) } } + + private getConfig(name: string, defaultValue?: any) { + return Config.get( + `database.connections.${ + this.connection === 'default' + ? Config.get('database.default') + : this.connection + }.${name}`, + defaultValue + ) + } } diff --git a/src/commands/DbSeedCommand.ts b/src/commands/DbSeedCommand.ts index 8e1339b..abcc434 100644 --- a/src/commands/DbSeedCommand.ts +++ b/src/commands/DbSeedCommand.ts @@ -48,16 +48,16 @@ export class DbSeedCommand extends BaseCommand { await DB.runSeeders({ task, classes: this.classes }) - await task.run().finally(async () => { - const dbName = await DB.getCurrentDatabase() - - await DB.close() - - console.log() - this.logger.success( - `Database ({yellow} "${dbName}") successfully seeded.` - ) - }) + await task + .run() + .then(async () => { + const dbName = await DB.getCurrentDatabase() + console.log() + this.logger.success( + `Database ({yellow} "${dbName}") successfully seeded.` + ) + }) + .finally(() => DB.close()) } private getConfig(name: string, defaultValue?: any) { diff --git a/src/commands/DbWipeCommand.ts b/src/commands/DbWipeCommand.ts index d7354bd..2ef51ae 100644 --- a/src/commands/DbWipeCommand.ts +++ b/src/commands/DbWipeCommand.ts @@ -55,14 +55,17 @@ export class DbWipeCommand extends BaseCommand { ) } - await task.run().finally(async () => { - const dbName = await DB.getCurrentDatabase() + await task + .run() + .then(async () => { + const dbName = await DB.getCurrentDatabase() - await DB.close() - - console.log() - this.logger.success(`Database ({yellow} "${dbName}") successfully wiped.`) - }) + console.log() + this.logger.success( + `Database ({yellow} "${dbName}") successfully wiped.` + ) + }) + .finally(() => DB.close()) } private getConfig(name: string, defaultValue?: any) { diff --git a/src/commands/MigrationRevertCommand.ts b/src/commands/MigrationRevertCommand.ts index 141c453..7ded47e 100644 --- a/src/commands/MigrationRevertCommand.ts +++ b/src/commands/MigrationRevertCommand.ts @@ -38,12 +38,15 @@ export class MigrationRevertCommand extends BaseCommand { } const DB = Database.connection(this.connection) - const dbName = await DB.getCurrentDatabase() - await DB.revertMigrations().finally(() => DB.close()) + await DB.revertMigrations() + .then(async () => { + const dbName = await DB.getCurrentDatabase() - this.logger.success( - `Successfully reverted migrations on ({yellow} "${dbName}") database.` - ) + this.logger.success( + `Successfully reverted migrations on ({yellow} "${dbName}") database.` + ) + }) + .finally(() => DB.close()) } } diff --git a/src/commands/MigrationRunCommand.ts b/src/commands/MigrationRunCommand.ts index dec3ae3..b7a4bc9 100644 --- a/src/commands/MigrationRunCommand.ts +++ b/src/commands/MigrationRunCommand.ts @@ -38,12 +38,15 @@ export class MigrationRunCommand extends BaseCommand { } const DB = Database.connection(this.connection) - const dbName = await DB.getCurrentDatabase() - await DB.runMigrations().finally(() => DB.close()) + await DB.runMigrations() + .then(async () => { + const dbName = await DB.getCurrentDatabase() - this.logger.success( - `Successfully ran migrations on ({yellow} "${dbName}") database.` - ) + this.logger.success( + `Successfully ran migrations on ({yellow} "${dbName}") database.` + ) + }) + .finally(() => DB.close()) } }