databaseManager->getConnection($sourceConnection); $targetConn = $this->databaseManager->getConnection($targetConnection); // Compare the schemas $comparator = new SchemaComparator($sourceConn, $targetConn); $difference = $comparator->compare($sourceSchema, $targetSchema); if (! $difference->hasDifferences()) { echo "No schema differences found.\n"; return ExitCode::SUCCESS; } // Generate the migration $className = $this->toClassName($name); $version = MigrationVersion::fromDateTime(new \DateTimeImmutable()); $description = $name; $migrationCode = $this->migrationGenerator->generateMigration( $difference, $className, $description, $version ); // Save the migration to a file $migrationPath = $this->pathProvider->resolvePath("src/Domain/{$domain}/Migrations"); if (! is_dir($migrationPath)) { mkdir($migrationPath, 0755, true); } $fileName = "{$className}.php"; $filePath = $migrationPath . '/' . $fileName; if (file_exists($filePath)) { echo "Error: Migration file already exists: {$filePath}\n"; return ExitCode::SOFTWARE_ERROR; } file_put_contents($filePath, $migrationCode); echo "Migration created: {$filePath}\n"; // Display a summary of the differences echo "\nSchema Difference Summary:\n"; echo str_repeat('-', 80) . "\n"; $summary = $difference->getSummary(); echo "Missing tables: {$summary['missing_tables']}\n"; echo "Extra tables: {$summary['extra_tables']}\n"; echo "Modified tables: " . count($difference->tableDifferences) . "\n"; echo "\nFor detailed differences, use the db:schema:diff command.\n"; return ExitCode::SUCCESS; } catch (\Throwable $e) { echo "Error creating migration: {$e->getMessage()}\n"; if (isset($_ENV['APP_DEBUG']) && $_ENV['APP_DEBUG']) { echo $e->getTraceAsString() . "\n"; } return ExitCode::SOFTWARE_ERROR; } } /** * Convert a string to a class name */ private function toClassName(string $name): string { // Convert "Create Users Table" to "CreateUsersTable" return str_replace(' ', '', ucwords(str_replace('_', ' ', $name))); } }