让 Phing 的 dbdeploy 任务在增量错误时自动回滚
我正在使用 Phing 的 dbdeploy 任务 到 管理我的数据库架构。只要我的增量文件的查询中没有错误,这就可以正常工作。
但是,如果出现错误,dbdeploy 将仅运行增量文件直至出现错误的查询,然后中止。这让我有些沮丧,因为我必须手动回滚更改日志表中的条目。如果不这样做,dbdeploy 将假定在后续尝试中迁移成功,因此任何重试都不会执行任何操作。
所以问题是,是否有任何方法可以让 dbdeploy 使用事务,或者您是否可以建议任何其他方法来在发生错误时自动回滚 phing?
注意:我对 Phing 不太精通,因此如果这涉及编写自定义任务,则非常感谢任何示例代码或包含更多信息的 url。谢谢
I am using Phing's dbdeploy task to manage my database schema. This is working fine, as long as there is no errors in the queries of my delta files.
However, if there is an error, dbdeploy will just run the delta files up to the query with the error and then abort. This causes me some frustration, because I have to manually rollback the entry in the changelog table then. If I don't, dbdeploy will assume the migration was successful on a subsequent try, so any retries will do nothing.
So the question is, is there any way to get dbdeploy use transactions or can you suggest any other way to have phing rollback automatically when an error occurs?
Note: I'm not that proficient with Phing, so if this involves writing a custom task, any example code or a url with further information is highly appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
(如果您仍然在那里...)关于数据库转储任务的 phing,请使用数据库的转储实用程序并创建一个 phing 任务。我主要使用 postgres 并在我的 phing build.xml 中包含以下内容:
(if you're still out there...) Regarding phing for a db dump task, use the db's dump utility and create a phing task. I use postgres mainly and have this in my phing build.xml:
解决问题的最简单方法是使用 pdoexec 任务,它默认在事务中运行 sql 脚本。当错误发生时,数据库引擎将自动回滚您的更改(即使是更改日志表上的更改 - 数据库将处于以前的状态)
示例:
The simplest way of solving your problem is to use pdoexec task which by default runs sql script in transaction. When error occurs the database engine will automatically rollback your changes (even those on change log table - database will be in previous state)
Example:
我知道,这是非常古老的线程,但也许它会被其他人充分利用。
您可以使用 try->catch 语句来实现该问题的解决方案。
我的例子:
I know, this is very old thread, but maybe it will be use full for someone else.
You can use try->catch statements to implement a solution for that.
My example :
为什么不编写一系列撤消增量并添加一个在其他任务失败时运行的 phing 任务?
Why not write a series of undo deltas and add a phing task that runs on failure of the other task?
你真的应该看看 capistrano 。
TomTom:您在这里遗漏了一些东西:当然必须在模式更改之前进行备份 - 但是如何处理在您认为一切正常的同时插入的新数据?我并不是说有一个很好的工具可以解决这个问题,但这个问题在现实生活中确实存在。
you really should take a look at capistrano.
TomTom: you are missing something here: the backup before schema change of course has to be made - but what to do with the NEW data that was inserted meanwhile you were thinking that everything is ok? I do not say, tthat there is a good tool for this problem, but the problem exists in real life.
执行此操作的“正确”方法是在架构更改之前进行备份,然后在出现错误时回滚。
您没有说您使用什么数据库 - 但我会想知道事务中是否支持所有架构更改。大多数大腿末端 SQL 数据库(oracle、db2、sql server)在所有情况下都不会这样做,这是有充分理由的。跨行为模式更改确实非常困难并且非常耗费资源。
The "proper" way to do this is a backup before schema change, then rollback in case of error.
You dont say what db you use - but it would wonder me if all schema changes would be supported in transactions. Mos thigh end SQL databases (oracle, db2, sql server) dont do that in all cases for really good reasons. Transacitonal schema changes are REALLY hard and REALLY resouce intensive.