从 Doctrine 迁移中获取 SQL
我一直在研究一种获取由生成的迁移文件构建的 SQL 语句的方法。它们扩展了 Doctrine_Migration_Base。本质上我想将 SQL 保存为更改脚本。
执行路径引导我到 Doctrine_Export,它具有构建 SQL 语句并执行它们的方法。我找不到只要求他们的方法。 Doctrine_Export 中的导出方法仅适用于 Doctrine_Record 模型,不适用于迁移脚本。
从命令行“./doctrine migrate version#”,路径为:
- Doctrine_Cli::run(cmd)
- Doctrine_Task_Migrate::setArguments(args)
- Doctrine_Task_Migrate::execute()
- Doctrine_Migration::migrate(to)
- Doctrine_Migration_Process::Doctrine_Export::various 使用 sql 创建、删除、更改方法 等价物。
以前有人解决过这个问题吗?我真的不想更改 Doctrine 基本文件。非常感谢任何帮助。
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 found 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个开发服务器,并在其上进行迁移,同时存储 SQL 跟踪吗?您不必保留结果,但您会获得每个命令的列表。
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.
考虑到 Rob Farley 的建议,我修改了:
当调用执行方法时,会检查可选参数“dryRun”。如果属实
然后创建一个“Doctrine_Connection_Profiler”实例。然后将“dryRun”值传递给
'Doctrine_Core::migrate' 方法。 “dryRun”值为 true 允许在执行完 SQL 语句后回滚更改。当方法返回时,分析器会解析非空 SQL 语句
不包含“migration_version”的内容将被保存并显示到终端。
Taking into account Rob Farley's suggestion, I modified:
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.