0

换句话说,我想知道在运行相关迁移之前确保self.down 实际上回滚self.up 的最佳方法。

如果我需要回滚迁移但self.down不能达到目的,我该怎么办?

处理具有潜在破坏性的迁移时,最佳做法是什么?只是数据库备份?

谢谢,杜乔。

4

4 回答 4

3

您应该在不应包含实时数据的开发数据库上进行开发。因此,数据是否被破坏并不重要,因为您可以轻松地再次生成它?

如果您发现自己的开发数据很重要但并不理想,那么数据库备份可能是合适的。

于 2011-08-17T16:52:44.210 回答
1

Typically migrations should contain only schema changes. In that case it should be very safe & easy to run the migrations in the dev/test environment. If something goes wrong you can alway re-create the database and populate it with some test data. But if you have some data related migrations to be tested, things might go wrong when you actually run them on production.

In that case as you mentioned database backup is what you should rely on. Come with a proper & quick restore mechanism before deploying.

于 2011-08-17T16:53:55.737 回答
0

为确保迁移行为符合您的要求,您应该在您的开发环境中进行试验。

运行命令

rake -T

向您展示可用的任务,例如

rake db:migrate

或者

rake db:rollback
于 2011-08-17T17:06:16.833 回答
0

每个迁移都在一个事务中运行。记在脑子里。这意味着,如果在单个迁移中出现问题,迁移将回滚(如果有任何后续,则不会执行)。

为了测试迁移,无论是它up还是down我插入了大量的 puts 语句,以检查一切是否正常,然后在我的最后一行中我提出了一个异常。这会让 rails 认为迁移失败,并且会回滚操作(就好像从未发生过一样)。

当我确定一切正常时,我删除了提升线并让迁移真正起作用。在您的情况下,您将使用加注进行测试,删除加注并且不再运行它我假设:)

希望这可以帮助。

于 2011-08-17T22:37:13.343 回答