diff --git a/package-lock.json b/package-lock.json index c194e20..e912be2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/database", - "version": "4.43.0", + "version": "4.44.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/database", - "version": "4.43.0", + "version": "4.44.0", "license": "MIT", "dependencies": { "@faker-js/faker": "^8.4.0", diff --git a/package.json b/package.json index 8f969d9..f376f28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/database", - "version": "4.43.0", + "version": "4.44.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 b2b6ff6..d3adbfa 100644 --- a/src/commands/DbFreshCommand.ts +++ b/src/commands/DbFreshCommand.ts @@ -17,6 +17,13 @@ export class DbWipeCommand extends BaseCommand { }) public connection: string + @Option({ + default: false, + signature: '--with-seeders', + description: 'Run seeders at the end.' + }) + public withSeeders: boolean + public static signature(): string { return 'db:fresh' } @@ -27,6 +34,12 @@ export class DbWipeCommand extends BaseCommand { public async handle(): Promise { await Artisan.call(`db:wipe --connection ${this.connection}`) + console.log() await Artisan.call(`migration:run --connection ${this.connection}`) + + if (this.withSeeders) { + console.log() + await Artisan.call(`db:seed --connection ${this.connection}`) + } } } diff --git a/tests/unit/commands/DbFreshCommandTest.ts b/tests/unit/commands/DbFreshCommandTest.ts index f007922..7c11c66 100644 --- a/tests/unit/commands/DbFreshCommandTest.ts +++ b/tests/unit/commands/DbFreshCommandTest.ts @@ -22,4 +22,16 @@ export default class DbFreshCommandTest extends BaseCommandTest { output.assertLogged('[ WIPING DATABASE ]') output.assertLogged('[ RUNNING MIGRATIONS ]') } + + @Test() + public async shouldBeAbleToRunDbFreshCommandAndSeedersAtTheEnd({ command }: Context) { + const output = await command.run('db:fresh --with-seeders --connection=fake', { + path: Path.fixtures('consoles/db-console.ts') + }) + + output.assertSucceeded() + output.assertLogged('[ WIPING DATABASE ]') + output.assertLogged('[ RUNNING MIGRATIONS ]') + output.assertLogged('[ SEEDING DATABASE ]') + } }