Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper method for committing schema.rb

The general consensus is that when migrating you should check schema.rb into version control.

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

My question is this- if my senior dev creates a migration & checks schema.rb, I pull the repo down and migrate on my end and it shows schema.rb has been changed- do I also commit my version of schema.rb and check that into version control as well?

like image 946
Crash Avatar asked Apr 11 '14 16:04

Crash


People also ask

Should you commit schema RB?

You are doing only a big mistake that you can correct quickly: you should really commit the file db/schema. rb in your repository. This is standard for rails application.

What is schema RB?

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.

What is RB in git?

ruby-on-rails. git.

What is RB in database?

rb file is the place where you can populate your database with some sample records. So after doing a rake db:reset, the database will contain all the records you created in the seeds. rb file. However there are two problems with the default setup.


1 Answers

In theory, your schema.rb should be identical to the one that Senior Dev has committed, after you do the migration. If it isn't, then one of two things have happened:

  • Senior Dev actually forgot to commit schema.rb
  • The migration made a change that is not recorded by schema.rb in a consistent way (there are many creative uses of migrations that might lead to this, let alone bugs).

You should double check that Senior Dev has, in fact, committed schema.rb after they ran the migration. If they have, you should throw away the changes on your version of schema.rb in favour of theirs. If they have NOT, then you should commit your version of schema.rb, effectively correcting their mistake.

like image 123
Sigi Avatar answered Sep 28 '22 08:09

Sigi