Rails 迁移是否应该与 schema.rb 分开提交?
生成/编写/运行 Rails 数据库迁移后,迁移文件和 db/schema.rb 是否应该单独提交版本控制?
After generating / writing / running a Rails database migration, should the migration file and db/schema.rb
be committed to version control separately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
schema.rb
与迁移不同步,一些应该相似的 rake 任务可能会表现不同,例如:创建数据库后,如果运行:
rake db:migrate
- 它将运行迁移rake db:schema:load
- 它将使用schema.rb
重置数据库:
rake db:migrate:reset
- 重新创建一个一个运行迁移的数据库。rake db:reset
- 使用当前版本的schema.rb
重新创建数据库在这两种情况下,无论您选择哪个任务,结果都应该是相同的。通常,首选使用 schema.rb,因为它一步创建数据库,而不是传递每个单独的迁移,但如果它与迁移的版本不同,结果将会不同。
Some rake tasks that should be similar may behave differently if
schema.rb
is not in sync with migrations, for example:After creating the database, if you run:
rake db:migrate
- it'll run the migrationsrake db:schema:load
- it'll use theschema.rb
Reseting the database:
rake db:migrate:reset
- recreates the database running the migrations one by one.rake db:reset
- recreates the database using current version ofschema.rb
In both cases, no matter which task you choose, the result should be the same. Normally, using
schema.rb
is preferred since it creates the database in one step, instead of passing for every single migration, but if it's not the same version as the migrations the results will be different.我见过的大多数人都在一次提交中提交了它们。
这样对我来说更有意义。它确保在任何修订上运行
rake db:migrate
不会修改db/schema.rb
。Most people I've seen commit them in a single commit.
It makes more sense to me that way. It makes sure that running a
rake db:migrate
on any revision doesn't modifydb/schema.rb
.