我曾经以为 DB / schema.rb 中存储的数据库架构,使的Rails 项目的ActiveRecord 可以知道什么表/列它。
I used to think the db/schema.rb in a Rails project stored the database schema, so that ActiveRecord can know what table/column it has.
不过,早前我令人惊讶的发现我的项目运行正常后,我删除 DB / schema.rb !
But earlier I surprisingly noticed that my project runs normally after I delete db/schema.rb!
所以,因为的Rails 可以不用它的工作,是什么 schema.rb 真的?
So, since the Rails can work without it, what does schema.rb really do?
推荐答案在 schema.rb 供应主要有两个目的:
The schema.rb serves mainly two purposes:
它记录了数据库架构的最终当前状态。通常情况下,尤其是当你有不止一对夫妇迁移的,很难仅仅从单纯的迁移扣除架构。随着present schema.rb ,你可以去看看那里。 ActiveRecord的本身确实不使用它。运行时它会内省的数据库,因为这是更安全,而不是期望用户保持 schema.rb 最多最新的。然而,为了避免你的开发人员的困惑,你应该始终保持一个文件,该文件是最新的最新与您的迁移。
It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. With a present schema.rb, you can just have a look there. ActiveRecord itself will indeed not use it. It will introspect the database during runtime as this is much safer than to expect users to keep the schema.rb up-to-date. However to avoid confusion of your developers, you should always maintain a file that is up-to-date with your migrations.
据所使用的测试来填充数据库模式。作为这样的耙分贝:模式:转储常被作为耙的一部分运行测试:prepare 运行。其目的是测试数据库的模式发展现状数据库完全一致。
It is used by the tests to populate the database schema. As such a rake db:schema:dump is often run as part of the rake test:prepare run. The purpose is that the schema of the test database exactly matches the current development database.
更多推荐
导轨:什么呢schema.rb办?
发布评论