且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除 Rails 应用中的旧迁移文件

更新时间:2023-11-24 14:28:22

您不需要在 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.