删除 Rails 应用中的旧迁移文件 [英] Delete old migrations files in a Rails app

查看:35
本文介绍了删除 Rails 应用中的旧迁移文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果架构稳定,是否允许删除(或归档)Rails 应用程序中的旧迁移文件?

Is it permissible to delete (or archive) old migration files in a Rails app if the schema is stable?

我的迁移很多,我怀疑某处可能存在一些问题,因为我偶尔会在 Heroku 上迁移数据库时遇到问题.

My migrations are numerous and I suspect there may be some problem in there somewhere, because I occasionally have problems migrating the database on Heroku.

推荐答案

您不需要在 Rails 应用程序中保留旧的迁移文件,因为您的数据库架构应该在 schema.rb 或等效的 SQL 中捕获可用于重新生成架构的文件.

You don't need to keep around your old migration files in a Rails app, because your database schema should be captured either in schema.rb or an equivalent SQL file that can be used to regenerate your schema.

迁移不是您的数据库架构的权威来源.该角色属于 db/schema.rb 或 Active Record 通过检查数据库生成的 SQL 文件.它们不是为编辑而设计的,它们只是代表数据库的当前状态.

Migrations are not the authoritative source for your database schema. That role falls to either db/schema.rb or an SQL file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.

无需(而且很容易出错)通过重放整个迁移历史来部署应用的新实例.将当前模式的描述加载到数据库中更简单、更快捷,该描述位于 schema.rb 或 SQL 文件中.
此文件应进行版本控制并保存在源代码管理中.

There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema, which is in schema.rb or the SQL file.
This file should be versioned and kept in source control.

要设置自动生成 schema.rb,请通过 config.active_record.schema_format 设置修改 config/application.rb,可以是 :ruby 或 :sql.如果 :ruby 被选中,那么模式存储在 db/schema.rb 中.如果 :sql 被选中,模式将以本机 SQL 格式转储您的数据库.

To set up automatic schema.rb generation, modify config/application.rb by the config.active_record.schema_format setting, which may be :ruby or :sql. If :ruby is selected then the schema is stored in db/schema.rb. If :sql is selected, the schema is dumped out in native SQL format of your database.

这篇关于删除 Rails 应用中的旧迁移文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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