What's the best way to set up Git staging and production environments with separate databases? What's the best way to set up Git staging and production environments with separate databases? database database

What's the best way to set up Git staging and production environments with separate databases?


We use a cascading approach:

  1. Default settings are in a common "config" file.
  2. For each stage of development, it has its own configuration file, for example we have a config_prod and a config_dev.
  3. Each stage runs as a different (system) user, and for that user we set an environment variable PROJ_SETTINGS and point it to the file that we need to load.

The code then read the defaults, and then overrides them with whatever is available from the resource pointed to by the environment variable (if it exists).

Setting of this variable is taken care of by our normal devops/automation scripts. We have a few advantages:

  1. Keeps all configuration under version control.
  2. Easy to switch settings without modifying the source.


Yes gitignoring the database.yml file is an approach I've used in a few organizations.

We usually keep a database.yml.sample in source control so make it easier. Users just copy that to database.yml and modify as appropriate.