47 lines
1.6 KiB
PHP
Executable File
47 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
|
class MigrateFreshCommand extends Command
|
|
{
|
|
protected static $defaultName = 'migrate:fresh';
|
|
protected static $defaultDescription = 'Drop all tables and re-run all migrations';
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addOption('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed command should be re-run');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$output->writeln('<info>Iniciando limpeza do banco de dados (fresh)...</info>');
|
|
|
|
// 1. Wipe database
|
|
$wipeCommand = $this->getApplication()->find('db:wipe');
|
|
$wipeInput = new ArrayInput(['--force' => true]);
|
|
$wipeCommand->run($wipeInput, $output);
|
|
|
|
// 2. Run migrations
|
|
$migrateCommand = $this->getApplication()->find('migrate');
|
|
$migrateInput = new ArrayInput([]);
|
|
$migrateCommand->run($migrateInput, $output);
|
|
|
|
// 3. Optional seed
|
|
if ($input->getOption('seed')) {
|
|
$seedCommand = $this->getApplication()->find('db:seed');
|
|
$seedInput = new ArrayInput([]);
|
|
$seedCommand->run($seedInput, $output);
|
|
}
|
|
|
|
$output->writeln('<info>Operação migrate:fresh concluída com sucesso!</info>');
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|