First Commit
This commit is contained in:
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
|
||||
class DbListCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'db:list';
|
||||
protected static $defaultDescription = 'Lista todas as tabelas do banco de dados';
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$connection = Capsule::connection();
|
||||
$dbName = $connection->getDatabaseName();
|
||||
|
||||
$output->writeln("<info>Tabelas no banco de dados: {$dbName}</info>");
|
||||
|
||||
$tables = $connection->select('SHOW TABLES');
|
||||
$key = "Tables_in_{$dbName}";
|
||||
|
||||
if (empty($tables)) {
|
||||
$output->writeln('<info>Nenhuma tabela encontrada no banco de dados.</info>');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['Tabela', 'Total de Registros']);
|
||||
|
||||
foreach ($tables as $t) {
|
||||
$tableName = $t->$key;
|
||||
$count = $connection->table($tableName)->count();
|
||||
$table->addRow([$tableName, $count]);
|
||||
}
|
||||
|
||||
$table->render();
|
||||
$output->writeln("<info>Total de tabelas: " . count($tables) . "</info>");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user