本文介绍了数据库迁移回滚的有用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多人谈论数据库迁移,尤其是关于数据库回滚的可能性。

Many people talking about db migrations, especially about its rollback possibility.

我怀疑它是否有用,因为数据库的架构和模型紧密相连

I doubt, whether it is useful at all, because schema of db and model are tightly connected with application logic (MVC).

假设我已经完成了某些迁移的回滚。那又怎样呢?该应用程序将无法运行,因为其逻辑完全依赖于db。

Suppose i've done rollback of some migration. And what ? The application will not work, because its logic fully relies on db.

db迁移的回滚功能的用例是什么?

What are the use cases of rollback ability for db migrations ?

更新1

主要问题

创建迁移,例如 add_another_field_to_table。相反,每个迁移文件都完整描述了数据库中的每个表。当我需要更改数据库中的某些内容时,只需更改迁移文件,但不要回滚

I don't create the migrations, like "add_another_field_to_table". Instead, each migration file fully describes each table in DB. When i need to change something in my DB, i just change the migration file, but don't roll it back.

如果我回滚了迁移,它没有像版本控件那样使我回到过去。当计划变更并且回滚没有任何帮助时,我有很多工作。

Really, if i rollback the migration, it does't brings me back in time, like a version control does. I have a lot of work, when changes are planned and rollback gives me nothing.

推荐答案

回滚的重点是您回滚了代码和数据库同时进行。场景是您在生产服务器上升级代码和数据库,然后发现一个错误,您确实需要返回。因此,回滚代码并使用向下迁移回滚数据库。

The point of rollback is that you rollback code and DB at the same time. The scenario is you upgrade your code and your DB on your production server, then you find a bug and you really need to go back. So rollback your code and use your down migration to roll back your DB.

这篇关于数据库迁移回滚的有用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 11:04