Add --framework-only flag to migrate command and enhance framework-pull

🤖 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 05:00:27 +00:00
parent ae38320d9e
commit 94c68861cc
2 changed files with 178 additions and 37 deletions

View File

@@ -33,7 +33,7 @@ use App\RSpade\Core\Database\SqlQueryTransformer;
*/
class Maint_Migrate extends Command
{
protected $signature = 'migrate {--force} {--seed} {--step} {--path=*} {--production : Run in production mode, skipping snapshot requirements}';
protected $signature = 'migrate {--force} {--seed} {--step} {--path=*} {--production : Run in production mode, skipping snapshot requirements} {--framework-only : Run only framework migrations (system/database/migrations), skip snapshot, but run normalization}';
protected $description = 'Run migrations and maintenance commands';
@@ -54,8 +54,11 @@ class Maint_Migrate extends Command
// Check if we're in production mode (either via flag or environment)
$is_production = $this->option('production') || app()->environment('production');
// Only enforce snapshot protection in development mode without --production flag
$require_snapshot = !$is_production;
// Check if we're in framework-only mode
$is_framework_only = $this->option('framework-only');
// Only enforce snapshot protection in development mode without --production or --framework-only flag
$require_snapshot = !$is_production && !$is_framework_only;
// Check for migration mode if we require snapshot
if ($require_snapshot) {
@@ -80,9 +83,12 @@ class Maint_Migrate extends Command
$this->info('');
} elseif ($is_production) {
$this->info('🚀 Running in production mode (no snapshot protection)');
} elseif ($is_framework_only) {
$this->info('🔧 Running framework-only migrations (no snapshot protection)');
}
$this->info('Running migrations' . ($is_production ? ' (production mode)' : ' with maintenance commands') . '...');
$mode_desc = $is_production ? ' (production mode)' : ($is_framework_only ? ' (framework-only)' : ' with maintenance commands');
$this->info('Running migrations' . $mode_desc . '...');
// Get all the options
$force = $this->option('force');
@@ -104,8 +110,13 @@ class Maint_Migrate extends Command
return 1;
}
// Determine which migration paths to use for whitelist check
$paths_to_check = $is_framework_only
? [database_path('migrations')]
: MigrationPaths::get_all_paths();
// Check migration whitelist
if (!$this->checkMigrationWhitelist()) {
if (!$this->checkMigrationWhitelist($paths_to_check)) {
return 1;
}
@@ -127,7 +138,8 @@ class Maint_Migrate extends Command
}
// Run normalize_schema BEFORE migrations to fix existing tables
$requiredColumnsArgs = $is_production ? ['--production' => true] : [];
// Pass --production flag to skip snapshot in both production and framework-only modes
$requiredColumnsArgs = ($is_production || $is_framework_only) ? ['--production' => true] : [];
$this->info("\n🔧 Pre-migration normalization (fixing existing tables)...\n");
$normalizeExitCode = $this->call('migrate:normalize_schema', $requiredColumnsArgs);
@@ -149,8 +161,10 @@ class Maint_Migrate extends Command
$migrator = app('migrator');
$migrator->setOutput($bufferedOutput);
// Use all migration paths (framework + user)
$migrationPaths = MigrationPaths::get_all_paths();
// Use all migration paths (framework + user), or just framework if --framework-only
$migrationPaths = $is_framework_only
? [database_path('migrations')]
: MigrationPaths::get_all_paths();
// Run migrations one-by-one with normalization after each
$this->run_migrations_with_normalization($migrator, $migrationPaths, $step, $requiredColumnsArgs);
@@ -231,11 +245,11 @@ class Maint_Migrate extends Command
return $normalizeExitCode;
}
// Only run regenerate constants if not in production mode
// Run regenerate constants if not in production mode (framework-only still runs it)
if (!$is_production) {
// Disable query logging for regenerate_constants
AppServiceProvider::disable_query_echo();
$maintenanceExitCode = $this->runMaintenanceCommand('rsx:constants:regenerate');
if ($maintenanceExitCode !== 0) {
$this->error('Regenerate constants maintenance failed');
@@ -245,7 +259,7 @@ class Maint_Migrate extends Command
// In production mode, check manifest consistency with database
// Disable query logging for consistency check
AppServiceProvider::disable_query_echo();
$this->info("\n");
$consistency_check_exit = $this->call('rsx:migrate:check_consistency');
if ($consistency_check_exit !== 0) {
@@ -294,8 +308,10 @@ class Maint_Migrate extends Command
/**
* Check if all pending migrations are whitelisted
*
* @param array $paths Array of migration paths to check
*/
protected function checkMigrationWhitelist(): bool
protected function checkMigrationWhitelist(array $paths): bool
{
$whitelistPath = database_path('migrations/.migration_whitelist');
@@ -310,9 +326,9 @@ class Maint_Migrate extends Command
$whitelist = json_decode(file_get_contents($whitelistPath), true);
$whitelistedMigrations = array_keys($whitelist['migrations'] ?? []);
// Get all migration files from all paths
// Get all migration files from specified paths
$migrationFiles = [];
foreach (MigrationPaths::get_all_paths() as $path) {
foreach ($paths as $path) {
if (is_dir($path)) {
foreach (glob($path . '/*.php') as $file) {
$migrationFiles[] = basename($file);