Should I ignore schema.rb because extension differs on development/production OS?
Asked Answered
O

2

11

My database uses PostgreSQL. I develop on Mac and this line is needed:

  # db/schema.rb on Mac environment
  enable_extension "plpgsql"

However, the extension is not required on Linux.

In this case, should we just ignore schema.rb and generate that through db:migrate for both dev and production environments?

Oe answered 17/9, 2013 at 23:57 Comment(5)
It doesn't seem to hurt production.Oe
However, Git complains whenever pulling when I forget to git checkout db/schema.rbOe
No I pull from development, which has enable_extension. In production, I do the following: pull, migrate, git checkout schema.rb before I am able to pull the next time.Oe
It doesn't seem right to git checkout schema.rb every time, that's why it feels I should just ignore schema.rb :(Oe
I don't believe db/schema.rb is read in either the production or development environments. It's basically a way for the test environment to dump the schema and re-setup when it runs it's tests. More info: #9884929Meiosis
T
2

As far as I understood it, the problem is that the auto-generated schema.rb will differ on production and development, and therefore cause changed files in git, because of this extra line.

Is the line generated by the postgres adapter on mac ? If it's been added manually, I'd try to put it somewhere else, maybe in an initializer (where you could switch its use based on the platform via something from here: Detecting Operating Systems in Ruby ).

Tallia answered 15/1, 2014 at 13:6 Comment(1)
The changes generated on production should not be in version control. Nevertheless, if you use different databases in development, a change in that config will cause a different scheme.rb, and mess with your versioning. In this case, I'll ignore the scheme.rb if it is going to be a derivative file and not manually edited.Karakalpak
P
0

I would always use the migrations. schema.rb has the downside of being only ruby. If - for some reason - you have plain SQL in your migrations, maybe to use BIGSERIAL instead of SERIAL or so, you will get a problem with schema.rb. Switching to a SQL-based schema-dump only solves part of the problem, leaving possible needed data-corrections or data-seed out of the picture.

Pollinate answered 2/6, 2015 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.