addArgument('module', InputArgument::REQUIRED, 'O nome do módulo')
->addArgument('name', InputArgument::REQUIRED, 'O nome da migração (ex: create_posts_table)');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$module = strtolower($input->getArgument('module'));
$name = Str::snake($input->getArgument('name'));
$modulePath = dirname(__DIR__, 3) . "/modules/{$module}";
if (!is_dir($modulePath)) {
$output->writeln("Módulo '{$module}' não encontrado.");
return Command::FAILURE;
}
$migrationsPath = "{$modulePath}/database/migrations";
if (!is_dir($migrationsPath)) {
mkdir($migrationsPath, 0755, true);
}
// Busca o próximo número sequencial para o prefixo (SysCMS usa 001, 002...)
$existingFiles = glob("{$migrationsPath}/*.php");
$nextNumber = str_pad(count($existingFiles) + 1, 3, '0', STR_PAD_LEFT);
$fileName = "{$nextNumber}_{$name}.php";
$filePath = "{$migrationsPath}/{$fileName}";
$className = Str::studly($name);
$template = <<create('table_name', function (Blueprint \$table) {
\$table->bigIncrements('id');
// \$table->string('name');
\$table->timestamps();
});
}
public function down()
{
Capsule::schema()->dropIfExists('table_name');
}
}
PHP;
if (file_put_contents($filePath, $template)) {
$output->writeln("Migração criada com sucesso: modules/{$module}/database/migrations/{$fileName}");
return Command::SUCCESS;
}
$output->writeln("Falha ao criar o arquivo de migração.");
return Command::FAILURE;
}
}