- Add docker volume prune to deploy.sh to prevent stale code issues - Add automatic migrations and cache warmup to staging entrypoint - Fix nginx race condition by waiting for PHP-FPM before starting - Improve PHP healthcheck to use php-fpm-healthcheck - Add curl to production nginx Dockerfile for healthchecks - Add ensureSeedsTable() to SeedRepository for automatic table creation - Update SeedCommand to ensure seeds table exists before operations This prevents 502 Bad Gateway errors during deployment and ensures fresh code is deployed without volume cache issues.
82 lines
2.6 KiB
PHP
82 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Database\Seed;
|
|
|
|
use App\Framework\Console\ConsoleCommand;
|
|
use App\Framework\Console\ConsoleInput;
|
|
use App\Framework\Console\ExitCode;
|
|
|
|
final readonly class SeedCommand
|
|
{
|
|
public function __construct(
|
|
private SeedLoader $seedLoader,
|
|
private SeedRunner $seedRunner,
|
|
private SeedRepository $seedRepository
|
|
) {
|
|
}
|
|
|
|
#[ConsoleCommand('db:seed', 'Run database seeders')]
|
|
public function seed(ConsoleInput $input): ExitCode
|
|
{
|
|
$className = $input->getOption('class');
|
|
$fresh = $input->hasOption('fresh');
|
|
|
|
try {
|
|
// Ensure seeds table exists (auto-create if missing)
|
|
$this->seedRepository->ensureSeedsTable();
|
|
|
|
// Clear seeds table if --fresh option is provided
|
|
if ($fresh) {
|
|
echo "⚠️ Clearing seeds table (--fresh option)...\n";
|
|
$this->seedRepository->clearAll();
|
|
echo "✅ Seeds table cleared.\n\n";
|
|
}
|
|
|
|
if ($className !== null) {
|
|
// Run specific seeder
|
|
echo "Running seeder: {$className}\n";
|
|
$seeder = $this->seedLoader->load($className);
|
|
|
|
if ($seeder === null) {
|
|
echo "❌ Seeder '{$className}' not found or cannot be instantiated.\n";
|
|
|
|
return ExitCode::SOFTWARE_ERROR;
|
|
}
|
|
|
|
$this->seedRunner->run($seeder);
|
|
echo "✅ Seeder '{$className}' completed.\n";
|
|
} else {
|
|
// Run all seeders
|
|
echo "Running all seeders...\n\n";
|
|
$seeders = $this->seedLoader->loadAll();
|
|
|
|
if (empty($seeders)) {
|
|
echo "No seeders found.\n";
|
|
|
|
return ExitCode::SUCCESS;
|
|
}
|
|
|
|
echo sprintf("Found %d seeder(s):\n", count($seeders));
|
|
foreach ($seeders as $seeder) {
|
|
echo " - {$seeder->getName()}: {$seeder->getDescription()}\n";
|
|
}
|
|
echo "\n";
|
|
|
|
$this->seedRunner->runAll($seeders);
|
|
echo "\n✅ All seeders completed.\n";
|
|
}
|
|
|
|
return ExitCode::SUCCESS;
|
|
} catch (\Throwable $e) {
|
|
echo "❌ Seeding failed: " . $e->getMessage() . "\n";
|
|
echo "Error details: " . get_class($e) . "\n";
|
|
echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
|
|
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
|
|
|
|
return ExitCode::SOFTWARE_ERROR;
|
|
}
|
|
}
|
|
}
|