first commit
This commit is contained in:
71
app/Console/Commands/CheckSchemaChanges.php
Normal file
71
app/Console/Commands/CheckSchemaChanges.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user