Database configuration across developers!

Hi,

I have what might be a silly question but is there any way to put some
of the database configuration information into a separate file? For
instance, in config/database.yml I have:

developer_database: &developer_database
adapter: mysql
username: me
password: something
host: 127.0.0.1

development:
<<: *developer_database
database: foobar_development

test:
<<: *developer_database
database: foobar_test

This was done so that the database names are standardised across
developers but the details of the actual database connection are
modifiable by the developer (another developer will alter just the
details in developer_database).

What I’d like is to have the ‘development’ and ‘test’ entries in
config/database.yml (which is checked into a SVN repository) and then
the ‘developer_database’ defined in a config/developer_database.yml
file (which is not checked in); both of these being loaded and
“merged” to get the appropriate database configurations.

Does that make sense? How else do people deal with this?

Matt

Matthew D. wrote:

host: 127.0.0.1
developers but the details of the actual database connection are

Matt


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

database.yml is parsed by ERb before yaml loads it. You can just do
this:

<%= File.read(“dev_db.yml”) %>

development:
<<: *developer_database
database: foobar_development

test:
<<: *developer_database
database: foobar_test

production:
adapter: mysql
username: etc
password: etcagain
blah: blah


Ola B. (http://ola-bini.blogspot.com)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.

You can approach this a couple of ways. The database.yml file can hold
real ruby just like the other yml files so there are a couple of ways
to fix your problem:

  1. Put a file in a standard directory outside the svn repository and
    have it read in.
  2. Use environment variables

I think I like the environment variables approach better since that is
how other “system” settings are set (like whether or not the system is
in production, test or development modes).

On 3-Aug-06, at 8:04 AM, Matthew D. wrote:

Hi,

I have what might be a silly question but is there any way to put some
of the database configuration information into a separate file? For
instance, in config/database.yml I have:

Splitting out the config into separate files seems overly complicated.

In all of my projects I simply have a database.yml-sample file
checked into svn and an svn:ignore set on database.yml. Each
developer simply copies database.yml-sample to database.yml and edits
it for their local environment.

HTH,
Trevor

Trevor S.
http://somethinglearned.com

On Aug 3, 2006, at 11:15 AM, Ola B. wrote:

host: 127.0.0.1
What I’d like is to have the ‘development’ and ‘test’ entries in

<<: *developer_database
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.

Or let the defaults stay in the database.yml, but allow an override
in a separate file that isn’t kept in the repository:

vvv Copy the following two YAML maps to a file called config/

mydatabase.yml

login: &login
username: default_user
password: default_password

connection: &connection
host: 127.0.0.1
port: 3306

^^^ Copy the previous two YAML maps to a file called config/

mydatabase.yml

<%= file = File.join(RAILS_ROOT, “config”, “mydatabase.yml”)
IO.read(file) if File.exist?(file) %>

development:
adapter: mysql
database: app_development
<<: *login
<<: *connection

The I can override the connection from TCP to, say, Unix socket where
I need to. I haven’t yet had to replace the adapter in this way, but
the same holds true. You could even leave the production as:

production:
adapter: mysql
database: app_production
username: production_user
password: production_password
host: localhost
socket: /tmp/mysql.sock

But I think it’s a good thing to keep the real user/password out of
the repository completely.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

On 8/3/06, Matthew D. [email protected] wrote:

I have what might be a silly question but is there any way to put some
of the database configuration information into a separate file?

Thanks for all the answers. I answered it myself about 10 minutes
after sending the email (I use the ERb idea) which just goes to show
that it should be a “measure twice, cut once” sort of world!

Matt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs