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:
@@ -308,19 +308,31 @@ class Maint_Migrate extends Command
|
||||
*/
|
||||
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 (!file_exists($whitelistPath)) {
|
||||
if (!$foundAtLeastOne) {
|
||||
$this->warn('⚠️ No migration whitelist found. Creating one with existing migrations...');
|
||||
$this->createInitialWhitelist();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load whitelist
|
||||
$whitelist = json_decode(file_get_contents($whitelistPath), true);
|
||||
$whitelistedMigrations = array_keys($whitelist['migrations'] ?? []);
|
||||
|
||||
// Get all migration files from specified paths
|
||||
$migrationFiles = [];
|
||||
foreach ($paths as $path) {
|
||||
@@ -360,33 +372,52 @@ class Maint_Migrate extends Command
|
||||
|
||||
/**
|
||||
* Create initial whitelist with existing migrations
|
||||
* Creates separate whitelist files for framework and application migrations
|
||||
*/
|
||||
protected function createInitialWhitelist(): void
|
||||
{
|
||||
$whitelistPath = database_path('migrations/.migration_whitelist');
|
||||
|
||||
$whitelist = [
|
||||
'description' => 'This file tracks migrations created via php artisan make:migration',
|
||||
'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts',
|
||||
'migrations' => [],
|
||||
$whitelistLocations = [
|
||||
database_path('migrations/.migration_whitelist') => database_path('migrations'),
|
||||
base_path('rsx/resource/migrations/.migration_whitelist') => base_path('rsx/resource/migrations'),
|
||||
];
|
||||
|
||||
// Add all existing migrations from all paths to whitelist (for initial setup)
|
||||
foreach (MigrationPaths::get_all_paths() as $path) {
|
||||
if (is_dir($path)) {
|
||||
foreach (glob($path . '/*.php') as $file) {
|
||||
$filename = basename($file);
|
||||
$whitelist['migrations'][$filename] = [
|
||||
'created_at' => 'pre-whitelist',
|
||||
'created_by' => 'system',
|
||||
'command' => 'existing migration',
|
||||
];
|
||||
}
|
||||
$totalMigrations = 0;
|
||||
|
||||
foreach ($whitelistLocations as $whitelistPath => $migrationPath) {
|
||||
// Skip if migration directory doesn't exist
|
||||
if (!is_dir($migrationPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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));
|
||||
$this->info('✅ Created migration whitelist with ' . count($whitelist['migrations']) . ' existing migrations.');
|
||||
if ($totalMigrations === 0) {
|
||||
$this->info('✅ No existing migrations found. Empty whitelists created.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function runMaintenanceCommand($command, $arguments = [])
|
||||
|
||||
@@ -28,18 +28,13 @@ class Make_Migration_With_Whitelist_Command extends Command
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// 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
|
||||
? database_path('migrations')
|
||||
: base_path('rsx/resource/migrations');
|
||||
@@ -97,27 +92,33 @@ class Make_Migration_With_Whitelist_Command extends Command
|
||||
*/
|
||||
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
|
||||
if (!file_exists($this->whitelistPath)) {
|
||||
file_put_contents($this->whitelistPath, json_encode([
|
||||
if (!file_exists($whitelistPath)) {
|
||||
file_put_contents($whitelistPath, json_encode([
|
||||
'description' => 'This file tracks migrations created via php artisan make:migration',
|
||||
'purpose' => 'Prevents manually created migrations from running to avoid timestamp conflicts',
|
||||
'migrations' => []
|
||||
], JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
$whitelist['migrations'][$filename] = [
|
||||
'created_at' => now()->toIso8601String(),
|
||||
'created_by' => get_current_user(),
|
||||
'command' => 'php artisan make:migration:safe ' . $this->argument('name')
|
||||
];
|
||||
|
||||
|
||||
// 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
|
||||
$is_framework_dev = env('IS_FRAMEWORK_DEVELOPER', false);
|
||||
$is_framework_dev = config('rsx.code_quality.is_framework_developer', false);
|
||||
return $is_framework_dev
|
||||
? database_path('migrations')
|
||||
: base_path('rsx/resource/migrations');
|
||||
|
||||
Reference in New Issue
Block a user