Skip to content

Commit

Permalink
Merge pull request #154 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat(db:fresh): add option to run seeders
  • Loading branch information
jlenon7 authored Apr 24, 2024
2 parents 4632c96 + 6ef99a2 commit 4662932
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions src/commands/DbFreshCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -27,6 +34,12 @@ export class DbWipeCommand extends BaseCommand {

public async handle(): Promise<void> {
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}`)
}
}
}
12 changes: 12 additions & 0 deletions tests/unit/commands/DbFreshCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]')
}
}

0 comments on commit 4662932

Please sign in to comment.