简体   繁体   中英

Should a rails migration be committed separately from schema.rb?

生成/编写/运行Rails数据库迁移后,迁移文件和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 modify db/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 migrations

rake db:schema:load - it'll use the schema.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 of schema.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM