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 = [])
|
||||
|
||||
Reference in New Issue
Block a user