Fix migration whitelist paths after Laravel moved to system subdirectory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 06:38:46 +00:00
parent 6c7cc9bc4e
commit 08febbb5ea
2 changed files with 71 additions and 39 deletions

View File

@@ -308,19 +308,31 @@ class Maint_Migrate extends Command
*/ */
protected function checkMigrationWhitelist(array $paths): bool protected function checkMigrationWhitelist(array $paths): bool
{ {
$whitelistPath = database_path('migrations/.migration_whitelist'); // Load whitelists from both locations and merge them
$whitelistPaths = [
database_path('migrations/.migration_whitelist'), // Framework migrations
base_path('rsx/resource/migrations/.migration_whitelist'), // Application migrations
];
$whitelistedMigrations = [];
$foundAtLeastOne = false;
foreach ($whitelistPaths as $whitelistPath) {
if (file_exists($whitelistPath)) {
$foundAtLeastOne = true;
$whitelist = json_decode(file_get_contents($whitelistPath), true);
$migrations = array_keys($whitelist['migrations'] ?? []);
$whitelistedMigrations = array_merge($whitelistedMigrations, $migrations);
}
}
// If no whitelist exists yet, create one with existing migrations // If no whitelist exists yet, create one with existing migrations
if (!file_exists($whitelistPath)) { if (!$foundAtLeastOne) {
$this->warn('⚠️ No migration whitelist found. Creating one with existing migrations...'); $this->warn('⚠️ No migration whitelist found. Creating one with existing migrations...');
$this->createInitialWhitelist(); $this->createInitialWhitelist();
return true; return true;
} }
// Load whitelist
$whitelist = json_decode(file_get_contents($whitelistPath), true);
$whitelistedMigrations = array_keys($whitelist['migrations'] ?? []);
// Get all migration files from specified paths // Get all migration files from specified paths
$migrationFiles = []; $migrationFiles = [];
foreach ($paths as $path) { foreach ($paths as $path) {
@@ -360,33 +372,52 @@ class Maint_Migrate extends Command
/** /**
* Create initial whitelist with existing migrations * Create initial whitelist with existing migrations
* Creates separate whitelist files for framework and application migrations
*/ */
protected function createInitialWhitelist(): void protected function createInitialWhitelist(): void
{ {
$whitelistPath = database_path('migrations/.migration_whitelist'); $whitelistLocations = [
database_path('migrations/.migration_whitelist') => database_path('migrations'),
$whitelist = [ base_path('rsx/resource/migrations/.migration_whitelist') => base_path('rsx/resource/migrations'),
'description' => 'This file tracks migrations created via php artisan make:migration',
'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts',
'migrations' => [],
]; ];
// Add all existing migrations from all paths to whitelist (for initial setup) $totalMigrations = 0;
foreach (MigrationPaths::get_all_paths() as $path) {
if (is_dir($path)) { foreach ($whitelistLocations as $whitelistPath => $migrationPath) {
foreach (glob($path . '/*.php') as $file) { // Skip if migration directory doesn't exist
$filename = basename($file); if (!is_dir($migrationPath)) {
$whitelist['migrations'][$filename] = [ continue;
'created_at' => 'pre-whitelist', }
'created_by' => 'system',
'command' => 'existing migration', $whitelist = [
]; 'description' => 'This file tracks migrations created via php artisan make:migration',
} 'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts',
'migrations' => [],
];
// Add all existing migrations from this specific path
foreach (glob($migrationPath . '/*.php') as $file) {
$filename = basename($file);
$whitelist['migrations'][$filename] = [
'created_at' => 'pre-whitelist',
'created_by' => 'system',
'command' => 'existing migration',
];
}
// Only create whitelist if there are migrations in this location
if (!empty($whitelist['migrations'])) {
file_put_contents($whitelistPath, json_encode($whitelist, JSON_PRETTY_PRINT));
$count = count($whitelist['migrations']);
$totalMigrations += $count;
$location = str_replace(base_path() . '/', '', dirname($whitelistPath));
$this->info("✅ Created whitelist in {$location} with {$count} migration(s).");
} }
} }
file_put_contents($whitelistPath, json_encode($whitelist, JSON_PRETTY_PRINT)); if ($totalMigrations === 0) {
$this->info('✅ Created migration whitelist with ' . count($whitelist['migrations']) . ' existing migrations.'); $this->info('✅ No existing migrations found. Empty whitelists created.');
}
} }
protected function runMaintenanceCommand($command, $arguments = []) protected function runMaintenanceCommand($command, $arguments = [])

View File

@@ -28,18 +28,13 @@ class Make_Migration_With_Whitelist_Command extends Command
*/ */
protected $description = 'Create a new migration and add it to the whitelist'; protected $description = 'Create a new migration and add it to the whitelist';
/**
* The migration whitelist file path
*/
protected $whitelistPath = '/var/www/html/database/migrations/.migration_whitelist';
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
// Determine migration path based on framework developer flag // Determine migration path based on framework developer flag
$is_framework_dev = env('IS_FRAMEWORK_DEVELOPER', false); $is_framework_dev = config('rsx.code_quality.is_framework_developer', false);
$migration_path = $is_framework_dev $migration_path = $is_framework_dev
? database_path('migrations') ? database_path('migrations')
: base_path('rsx/resource/migrations'); : base_path('rsx/resource/migrations');
@@ -97,27 +92,33 @@ class Make_Migration_With_Whitelist_Command extends Command
*/ */
protected function addToWhitelist(string $filename): void protected function addToWhitelist(string $filename): void
{ {
// Get correct whitelist path based on framework developer flag
$is_framework_dev = config('rsx.code_quality.is_framework_developer', false);
$whitelistPath = $is_framework_dev
? database_path('migrations/.migration_whitelist')
: base_path('rsx/resource/migrations/.migration_whitelist');
// Ensure whitelist file exists // Ensure whitelist file exists
if (!file_exists($this->whitelistPath)) { if (!file_exists($whitelistPath)) {
file_put_contents($this->whitelistPath, json_encode([ file_put_contents($whitelistPath, json_encode([
'description' => 'This file tracks migrations created via php artisan make:migration', 'description' => 'This file tracks migrations created via php artisan make:migration',
'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts', 'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts',
'migrations' => [] 'migrations' => []
], JSON_PRETTY_PRINT)); ], JSON_PRETTY_PRINT));
} }
// Load existing whitelist // Load existing whitelist
$whitelist = json_decode(file_get_contents($this->whitelistPath), true); $whitelist = json_decode(file_get_contents($whitelistPath), true);
// Add new migration with metadata // Add new migration with metadata
$whitelist['migrations'][$filename] = [ $whitelist['migrations'][$filename] = [
'created_at' => now()->toIso8601String(), 'created_at' => now()->toIso8601String(),
'created_by' => get_current_user(), 'created_by' => get_current_user(),
'command' => 'php artisan make:migration:safe ' . $this->argument('name') 'command' => 'php artisan make:migration:safe ' . $this->argument('name')
]; ];
// Save updated whitelist // Save updated whitelist
file_put_contents($this->whitelistPath, json_encode($whitelist, JSON_PRETTY_PRINT)); file_put_contents($whitelistPath, json_encode($whitelist, JSON_PRETTY_PRINT));
} }
/** /**
@@ -130,7 +131,7 @@ class Make_Migration_With_Whitelist_Command extends Command
} }
// Return path based on framework developer flag // Return path based on framework developer flag
$is_framework_dev = env('IS_FRAMEWORK_DEVELOPER', false); $is_framework_dev = config('rsx.code_quality.is_framework_developer', false);
return $is_framework_dev return $is_framework_dev
? database_path('migrations') ? database_path('migrations')
: base_path('rsx/resource/migrations'); : base_path('rsx/resource/migrations');