Files
dockerfluxodecaixapro/app/Console/Commands/DbShowCommand.php
T
2026-09-01 10:46:29 -03:00

45 lines
1.3 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 Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Console\Helper\Table;
class DbShowCommand extends Command
{
protected static $defaultName = 'db:show';
protected static $defaultDescription = 'Exibe informações sobre o banco de dados';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$connection = Capsule::connection();
$dbName = $connection->getDatabaseName();
$output->writeln("<info>Banco de Dados: {$dbName}</info>");
$output->writeln("Driver: " . $connection->getDriverName());
$tables = $connection->select('SHOW TABLE STATUS');
$table = new Table($output);
$table->setHeaders(['Tabela', 'Engine', 'Rows', 'Size (MB)', 'Collation']);
foreach ($tables as $t) {
$size = round(($t->Data_length + $t->Index_length) / 1024 / 1024, 2);
$table->addRow([
$t->Name,
$t->Engine,
$t->Rows,
$size,
$t->Collation
]);
}
$table->render();
return Command::SUCCESS;
}
}