flag_file)) { $this->error('[WARNING] No migration session in progress!'); $this->info('Nothing to commit.'); return 1; } $session_info = json_decode(file_get_contents($this->flag_file), true); $started_at = $session_info['started_at'] ?? 'unknown'; $this->info(' Migration session started at: ' . $started_at); // Check for unran migrations $this->info("\n Checking for unran migrations..."); $unran_migrations = $this->check_unran_migrations(); if (!empty($unran_migrations)) { $this->error('[ERROR] Found unran migration files:'); foreach ($unran_migrations as $migration) { $this->error(' - ' . $migration); } $this->info(''); $this->warn('Please either:'); $this->warn(' 1. Run them with: php artisan migrate'); $this->warn(' 2. Remove the migration files'); return 1; } $this->info('[OK] All migrations have been executed.'); // Run schema inspection in development mode if (app()->environment() !== 'production') { $this->info("\n Running database schema standards check..."); $checker = new SchemaQualityChecker(); $violations = $checker->check(); if ($checker->has_violations()) { $this->error('[ERROR] Schema standards check failed with ' . $checker->get_violation_count() . ' violation(s):'); $this->info(''); // Display violations $grouped = $checker->get_violations_by_severity(); foreach (['critical', 'high', 'medium', 'low'] as $severity) { if (!empty($grouped[$severity])) { $this->line(strtoupper($severity) . ' VIOLATIONS:'); foreach ($grouped[$severity] as $violation) { $this->line($violation->format_output()); } } } $this->info(''); $this->error('[ERROR] Rolling back migration session due to schema violations...'); // Execute rollback $this->call('migrate:rollback'); $this->info(''); $this->warn('[WARNING] Migration has been rolled back. Fix the schema violations and try again.'); return 1; } $this->info('[OK] Schema standards check passed.'); } $this->info("\n Committing migration changes..."); try { // Step 1: Remove backup directory if (is_dir($this->backup_dir)) { $this->info('[1] Removing backup snapshot...'); $this->run_privileged_command(['rm', '-rf', $this->backup_dir]); } // Step 2: Remove migration flag $this->info('[2] Removing migration flag...'); unlink($this->flag_file); // Success $this->info(''); $this->info('[OK] Migration changes committed successfully!'); $this->info(''); $this->line('• The backup has been deleted'); $this->line('• Migration mode has been disabled'); $this->line('• The web UI is now accessible'); $this->info(''); // Run post-migration tasks in development mode if (app()->environment() !== 'production') { // Regenerate model constants from enum definitions $this->info('Regenerating model constants...'); $this->call('rsx:constants:regenerate'); // Recompile bundles (must use passthru for fresh process) $this->newLine(); $this->info('Recompiling bundles...'); passthru('php artisan rsx:bundle:compile'); } return 0; } catch (\Exception $e) { $this->error('[ERROR] Failed to commit: ' . $e->getMessage()); return 1; } } /** * Run a maintenance artisan command */ protected function runMaintenanceCommand(string $command): void { try { $this->call($command); } catch (\Exception $e) { $this->warn("Warning: Could not run maintenance command {$command}: " . $e->getMessage()); } } /** * Check for unran migrations */ protected function check_unran_migrations(): array { $unran = []; // Get list of migration files from all paths $files = []; foreach (MigrationPaths::get_all_paths() as $path) { if (is_dir($path)) { $path_files = glob($path . '/*.php'); if ($path_files) { $files = array_merge($files, $path_files); } } } // Get list of already run migrations from database $table = config('database.migrations', 'migrations'); $ran_migrations = DB::table($table)->pluck('migration')->toArray(); // Check each file foreach ($files as $file) { $filename = basename($file, '.php'); if (!in_array($filename, $ran_migrations)) { $unran[] = $filename; } } return $unran; } }