Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right approach to deal with Rails db/schema.rb file in GIT?

Should we include schema.rb while commiting to GIT? or should we ignore it? what is the right approach?

like image 933
rubyprince Avatar asked Jun 23 '11 06:06

rubyprince


People also ask

What is schema RB in rails?

The schema. rb serves mainly two purposes: 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 deduce the schema just from the migrations alone. With a present schema.


1 Answers

Well the standard schema.rb file for Rails 2 has this at the end of the comment block at the top of the file:

# It's strongly recommended to check this file into your version control system. 

The Rails 3 schema.rb that I have kicking around says the same thing. I think the comment says it all.


Update in response to comments: Yes, mistakes can be made and you can get conflicting changes and bugs mangling your schema.rb but that's why you want it under revision control, revision control allows you to keep track of everything and backup when needed. There is only one thing in your entire source tree that specifies your database schema and that is schema.rb. Your database schema absolutely is a critical artifact and anything that important needs to be tracked in revision control.

Any update/merge problems with schema.rb should be sorted out just by sorting out your conflicting migrations so schema.rb will get fixed as a side effect of fixing the real problem.

Yes, schema.rb is a generated file but it is only generated in the sense that your text editor generates your pancake.rb model file or an unedited scaffold file is generated.

Yes, you could rebuild your schema.rb file by building a new database and then running all of your migrations. But, you should clear out your old migrations now and then to avoid having to check hundreds of migration files every time you rake db:migrate so "rebuild and run all the migrations" often isn't an option in a highly active project.

like image 54
mu is too short Avatar answered Oct 15 '22 00:10

mu is too short