Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to put db/schema.rb to .gitignore list ?? [closed]

Tags:

so what I'm suggesting in my job, is to put db/schema.rb into .gitignore file, so we don't have (time to time) merging problems.

There are some concerns that if something terrible happen (meteor fall from the sky right on the DB server and simultaneously all the db/migrete files are corrupt) we could loose the schema, and we will have to use rake db:purge (to reuse the schema.rb). I agree that this is possible and it's a good argument, but it shouldn't be problem because db/schema.rb is generated each time we do rake db:migrate. So even if we won't push schema.rb on server, we are pushing migrations add running db:migrate each time we are deploying with DB changes and with that db:migrate rails will automatically generate schema.rb on server side, and that schema.rb sits on the server unchanged until we do another db:migrate .

so whats your opinion, should we or should we not put the db/schema.rb into git ignore ?

thank you

like image 528
equivalent8 Avatar asked Jun 29 '11 11:06

equivalent8


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 used for?

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.


2 Answers

I would always suggest to keep schema.rb in version contol, since tasks like rake db:schema:load depend on it being there.

About the conflicts, are you talking about the schema version conflicts? These are easily mitigated using the merge algorithm showed here: http://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html

Other conflicts, like column definition switching locations can easily be avoided by being careful what you commit to the repository.

like image 105
Martijn Avatar answered Mar 03 '23 03:03

Martijn


You should put in a VCS whatever you need to reproduce an operational environment.
If, for rebuilding your application, you need to have the right schema.rb (at the right version), then yes, it can be versionned.

But if you can get it back through another process, then it is better backed up through some other referential than a VCS.

like image 42
VonC Avatar answered Mar 03 '23 01:03

VonC