我可以删除所有迁移文件并从头开始吗? [英] Can I delete all migration files and start from scratch?

查看:39
本文介绍了我可以删除所有迁移文件并从头开始吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rails-API 应用程序,我将在很长一段时间后重新部署它.该应用程序是非生产的,但我已准备好部署生产版本.我想基本上删除所有迁移文件并使用架构从头开始,这种方法有什么问题吗?假设我可以做到这一点,我需要将 schema.rb 更改为什么?这是一种常见的做法吗?对我来说似乎很合理.

I have a Rails-API app that I'm going to re-deploy after a long time. The app is non-production, but I am ready to deploy the production version. I want to basically delete all the migration files and start from scratch using the schema, is there any problem with this approach? Assuming I can do this, what do I need to alter the schema.rb to? Is this a common practice? Seems reasonable to me.

# what do I change the version param value to?
ActiveRecord::Schema.define(version: 20171129023538)  

推荐答案

迁移用于更新数据库或回滚到以前的版本.一旦迁移在所有环境中运行,它们就不会再被查看(当然,除非您手动处理 schema_migrations 表).运行所有迁移后,数据库的当前状态在 db/schema.rb(或 db/structure.sql)中,所以 schema.rb 是您从新数据库开始所需的全部内容.

Migrations are used to update your database or to rollback to previous versions. Once migrations have been run in all environments, they're never looked at again (unless you're manually messing around with the schema_migrations table of course). Once all your migrations have been run, the current state of the database is in db/schema.rb (or db/structure.sql) so schema.rb is all you need to start with a fresh database.

我倾向于每隔几个月清理一次旧迁移,以减少混乱.

I tend to clear out old migrations every couple months just to cut down on clutter.

就版本而言,您可以不理会它.只要它代表过去的时间(例如 2017-11-29 02:35:38)并且它低于需要运行的任何迁移(这不适用,因为您将它们全部删除)那么它是什么并不重要.

As far as the version goes, you can leave it alone. As long as it represent a time in the past (such as 2017-11-29 02:35:38) and it is lower than any migrations that need to be run (which doesn't apply as you're deleting them all) then it doesn't matter what it is.

继续清除所有迁移,它们已经反映在 schema.rb 中,如果您真的需要它们,您可以随时将它们从版本控制中挖掘出来.

Go ahead and clear out all the migrations, they're already reflected in schema.rb and you can always dig them out of revision control if you really need them.

这篇关于我可以删除所有迁移文件并从头开始吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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