first commit

This commit is contained in:
brusnitsyn
2026-03-23 00:51:38 +09:00
commit 07854e0a9d
110 changed files with 19528 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Console\Commands;
use App\Models\SourceDatabase;
use App\Services\SchemaComparisonService;
use Illuminate\Console\Command;
class CheckSchemaChanges extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'schema:check-changes {--database= : Specific database ID to check}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check for schema changes in source databases';
/**
* Execute the console command.
*/
public function handle(SchemaComparisonService $comparisonService): int
{
$databaseId = $this->option('database');
if ($databaseId) {
$databases = SourceDatabase::where('id', $databaseId)->get();
if ($databases->isEmpty()) {
$this->error("Database with ID {$databaseId} not found.");
return Command::FAILURE;
}
} else {
$databases = SourceDatabase::where('is_active', true)->get();
}
if ($databases->isEmpty()) {
$this->info('No source databases configured.');
return Command::SUCCESS;
}
$totalChanges = 0;
foreach ($databases as $database) {
$this->info("Checking schema changes for: {$database->name}");
$changes = $comparisonService->checkForChanges($database);
if ($changes->isEmpty()) {
$this->info(' No changes detected.');
} else {
$this->warn(" Found {$changes->count()} change(s):");
foreach ($changes as $change) {
$this->line(" - {$change['description']}");
}
$totalChanges += $changes->count();
}
}
$this->newLine();
$this->info("Total changes detected: {$totalChanges}");
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Console\Commands;
use App\Models\MigrationSchedule;
use App\Models\MigrationRun;
use App\Jobs\RunMigrationJob;
use Illuminate\Console\Command;
class RunMigration extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migration:run {schedule? : The schedule ID to run}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run a migration schedule immediately';
/**
* Execute the console command.
*/
public function handle(): int
{
$scheduleId = $this->argument('schedule');
if ($scheduleId) {
$schedule = MigrationSchedule::find($scheduleId);
if (!$schedule) {
$this->error("Schedule with ID {$scheduleId} not found.");
return Command::FAILURE;
}
$this->runSchedule($schedule);
} else {
// Run all due schedules
$schedules = MigrationSchedule::where('is_active', true)
->where(function ($query) {
$query->whereNull('next_run_at')
->orWhere('next_run_at', '<=', now());
})
->get();
if ($schedules->isEmpty()) {
$this->info('No schedules due to run.');
return Command::SUCCESS;
}
foreach ($schedules as $schedule) {
$this->runSchedule($schedule);
}
}
return Command::SUCCESS;
}
/**
* Run a specific schedule
*/
private function runSchedule(MigrationSchedule $schedule): void
{
$this->info("Running migration schedule: {$schedule->name}");
$migrationRun = MigrationRun::create([
'schedule_id' => $schedule->id,
'status' => 'pending',
'total_tables' => count($schedule->tables),
]);
RunMigrationJob::dispatch($migrationRun);
$this->info("Migration job dispatched. Run ID: {$migrationRun->id}");
}
}