rake db:schema:load与迁移 [英] rake db:schema:load vs. migrations

查看:76
本文介绍了rake db:schema:load与迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的问题很简单-随着应用程序变得越来越复杂,迁移是否会变得缓慢而麻烦,并且如果我们要调用的更简洁的rake db:schema:load,为什么迁移完全存在?

Very simple question here - if migrations can get slow and cumbersome as an app gets more complex and if we have the much cleaner rake db:schema:load to call instead, why do migrations exist at all?

如果上面的答案是迁移用于版本控制(逐步记录数据库更改),则随着应用变得越来越复杂而rake db:schema:load被更多使用,它们是否继续维护其主要功能?

If the answer to the above is that migrations are used for version control (a stepwise record of changes to the database), then as an app gets more complex and rake db:schema:load is used more instead, do they continue to maintain their primary function?

从这个问题的答案中:rake db:schema:load 将删除生产服务器上的数据,因此在使用它时要小心.

From the answers to this question: rake db:schema:load will delete data on a production server so be careful when using it.

推荐答案

迁移为数据库提供了前进和后退的步骤更改.在生产环境中,必须在部署期间对数据库进行增量更改:迁移为该功能提供了回滚故障保护功能.如果在生产服务器上运行rake db:schema:load,最终将删除所有生产数据.这是一个危险的习惯.

Migrations provide forward and backward step changes to the database. In a production environment, incremental changes must be made to the database during deploys: migrations provide this functionality with a rollback failsafe. If you run rake db:schema:load on a production server, you'll end up deleting all your production data. This is a dangerous habit to get into.

话虽如此,我相信偶尔崩溃"迁移是一种不错的做法.这需要删除旧的迁移,用一个迁移(非常类似于schema.rb文件)替换它们,并更新schema_migrations表以反映此更改. 执行此操作时请务必小心!如果不小心,可以轻松删除生产数据.

That being said, I believe it is a decent practice to occasionally "collapse" migrations. This entails deleting old migrations, replacing them with a single migration (very similar to your schema.rb file) and updating the schema_migrations table to reflect this change. Be very careful when doing this! You can easily delete your production data if you aren't careful.

作为旁注,我坚信您永远不应将数据创建放在迁移文件中. seed.rb文件可用于此或自定义rake或部署任务.将其放入迁移文件中会使数据库架构规范与数据规范混合在一起,并且在运行迁移文件时可能导致冲突.

As a side note, I strongly believe that you should never put data creation in the migration files. The seed.rb file can be used for this, or custom rake or deploy tasks. Putting this into migration files mixes your database schema specification with your data specification and can lead to conflicts when running migration files.

这篇关于rake db:schema:load与迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆