setHelp('This command drops all tables from the database without removing the database itself.')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the operation to run');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$input->getOption('force')) {
$output->writeln('Atenção: Este comando irá apagar TODAS as tabelas do banco de dados!');
$output->writeln('Use a opção --force para confirmar.');
return Command::FAILURE;
}
$output->writeln('Limpando banco de dados...');
$schema = Capsule::schema();
$tables = Capsule::connection()->select('SHOW FULL TABLES WHERE Table_type = "BASE TABLE"');
$dbName = Capsule::connection()->getDatabaseName();
$key = "Tables_in_{$dbName}";
Capsule::connection()->statement('SET FOREIGN_KEY_CHECKS = 0');
foreach ($tables as $table) {
$tableName = $table->$key;
$output->write("Dropando tabela: {$tableName}... ");
$schema->drop($tableName);
$output->writeln('OK');
}
Capsule::connection()->statement('SET FOREIGN_KEY_CHECKS = 1');
$output->writeln('Banco de dados limpo com sucesso!');
return Command::SUCCESS;
}
}