Skip to content

Commit

Permalink
Added the option reset --yes
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Nov 21, 2017
1 parent 2b10f97 commit fb3a3cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ migrate update --up-to=34
Creates/replace a database with the "base.sql" and apply ALL migrations

```bash
migrate reset
migrate reset --up-to=5
migrate reset # reset the database and apply all migrations scripts.
migrate reset --up-to=5 # reset the database and apply the migration version up to 5.
migrate reset --yes # reset the database without ask anything. Be careful!!
```

## Supported databases:
Expand Down
21 changes: 12 additions & 9 deletions src/Console/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ class ResetCommand extends ConsoleCommand
{
protected function configure()
{
parent::configure();
parent::configure();
$this
->setName('reset')
->setDescription('Create a fresh new database');

->setDescription('Create a fresh new database')
->addOption('yes', null, null, 'Answer yes to any interactive question');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('This will ERASE all of data in your data. Continue with this action? (y/N) ',
false);
if (!$input->getOption('yes')) {
$question = new ConfirmationQuestion(
'This will ERASE all of data in your data. Continue with this action? (y/N) ',
false
);

if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborted.');
if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborted.');

return;
return;
}
}

parent::execute($input, $output);
Expand All @@ -43,5 +47,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->handleError($ex, $output);
}
}

}

0 comments on commit fb3a3cd

Please sign in to comment.