I have been researching a way to get the SQL statements that are built by a generated Migration file. These extend Doctrine_Migration_Base. Essentially I would like to save the SQL as change scripts.
The execution path leads me to Doctrine_Export which has methods that build the SQL statement and executes them. I have fo开发者_StackOverflow社区und no way of asking for just them. The export methods found in Doctrine_Export only operate on Doctrine_Record models and not Migration scripts.
From the command line './doctrine migrate version#' the path goes:
- Doctrine_Cli::run(cmd)
- Doctrine_Task_Migrate::setArguments(args)
- Doctrine_Task_Migrate::execute()
- Doctrine_Migration::migrate(to)
- Doctrine_Migration_Process::Doctrine_Export::various create, drop, alter methods with sql equivalents.
Has anyone tackled this before? I really would not like to change Doctrine base files. Any help is greatly appreciated.
Could you make a dev server, and do the migration on that, storing a SQL Trace as you go?you don't have to keep the results, but you would get a list of every command.
Taking into account Rob Farley's suggestion, I modified:
- Doctrine_Core::migrate
- Doctrine_Task_Migrate::execute
When the execute method is called the optional argument 'dryRun' is checked. If true then a 'Doctrine_Connection_Profiler' instance is created. The 'dryRun' value is then passed onto the 'Doctrine_Core::migrate' method. The 'dryRun' value of true allows the changes to rollback when done executing the SQL statements. When the method returns, the profiler is parsed and non-empty SQL statements not containing 'migration_version' are saved and displayed to the terminal.
精彩评论