0

I've consulted the Ruby on Rails guide and stack overflow regarding setting up database.yml files and how they are set up but I'm running into a few snags with a particular database.yml file and how they interact with each other. Referring to the Ruby on Rails guides doesn't make this necessarily clear to me. I was hoping someone could fill the gaps for me.

Here is the database.yml file:

development:
  db_host: qa-db.company_name.com
  db_port: 5432
  db_name: company_staging
  db_user: rubyuser
  db_pass: generic_password

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  db_host: qa-db.company_name.com
  db_port: 5432
  db_name: company_test
  db_user: rubyuser
  db_pass: generic_password

testing:
  db_host: host
  db_port: 5432
  db_name: company_staging
  db_user: rubyuser
  db_pass: normal_password

selenium:
  db_host: host
  db_port: 5432
  db_name: company_selenium
  db_user: ruby
  db_pass: normal_password

production:
  db_host: qa-db.company_name.com
  db_port: 5432
  #db_name: company_production
  db_name: company_staging
  db_user: ruby
  db_pass: generic_password

Here is where I am getting confused. Just exactly how many databases are in this file? I mean this in terms of actual copies of data. The obvious answer would be that there are five databases. But I'm not too sure.

Look at the databases development, test, and production. The db_host for these three databases point to qa_db.company_name.com. This tells me that these three databases point to the same data. Development, test, and production contain the same data, meaning that if I were to drop the data in test for example, development and production would be wiped out too. But notice that these three databases have different db_names. Notice that development and production both have their db_names as company_staging while test has company_test. How does this affect the data? Are these different copies? Does the db_name change point to something different?

The testing database has db_host: host while the name is company_staging. If I were to log into this one. Which database would I be in?

This is murky territory for me so some clarification would really help me out. Thanks.

1 Answer 1

0

In a production environment you will have one and only one database defined unless you've got an unusual configuration that uses several different database servers.

In a development environment you will have two or three depending on your testing strategy. Usually development and test are defined, the others omitted since they're not relevant.

It's not really useful to have production defined in your development environment since you shouldn't be able to connect to that database in the first place, it should be heavily firewalled.

Normally config/database.yml is not included in your version control, instead some kind of "example" file is included instead. Since each developer on your team may have different credentials, it's best to omit this file and instead use your own custom version rather than have conflicts.

My recommendation is to store server-specific configuration on the server and link it in to the correct place when you deploy. For example shared/config/database.yml is symlinked into releases/NNNN/config/database.yml by a tool like Capistrano.

The long and the short of a database.yml file is Rails will look for a key in there that matches your current RAILS_ENV and use that configuration for the initial connection to your database. You can have as many as you want in there, but only the one correlating to your environment matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.