Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 302
Clucking Turtle Avatar asked Sep 17 '13 23:09

Clucking Turtle


People also ask

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.

What does rake db schema load do?

Unlike rake db:migrate that runs migrations that have not run yet, rake db:schema:load loads the schema that is already generated in db/schema. rb into the database. Always use this command when: You run the application for the first time.

What is structure SQL?

structure. sql instead is a SQL representation of the database and it depends on the specific database you selected. You only use the structure if you have specific database features that you need and that can't be represented by the schema.


1 Answers

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 ).

like image 66
Martin T. Avatar answered Nov 03 '22 23:11

Martin T.