views:

31

answers:

2

Looking for a way to cleanly override the values of databases.yml in Doctrine / Symfony in order to use my own local settings?

The idea is not touching databases.yml and using some sort of local unversioned file to override that default.

I'm trying to find out how without much success yet :/

A: 

For this kind of configuration file, that contains stuff that depends on the environment (dev, testing, staging, production, ...), I generally use one file per environment, and all are commited to source-control.

For example, I could have :

  • databases.yml == the development version, which will work when the project is checked out from source-control on a development computer.
  • databases.testing.yml
  • databases.staging.yml
  • databases.production.yml


Then, when building the .tag.gz (or similar) archive that will be deployed to a different environment, I copy the file that corresponds to the destination's to the default one.

For example, when creating an archive that will be deployed on the production server, I copy databases.production.yml to databases.yml, in the archive.

This way, the application always uses databases.yml, no matter what environment it's deployed on -- and all the possible configurations are commited to source-control.


Of course, this works much better if you are having some packaging / build process -- and don't just upload file to the servers via FTP by hand...

Pascal MARTIN
Thanks for the quick reply. You're info is useful but not in this specific case. I'm asking for a way to locally override the version-controlled databases.yml while i'm developing.. for deployment it's not a issue to edit it and put the correct values.
gnrfan
Well, while developping, I'm using the default databases.yml, which is under source-control -- no need to override anything, this way *(and no risk of committing something that shouldn't be)*
Pascal MARTIN
The idea came since I also develop with Django. Since the settings.py is just a Python module you end up attempting to import a local_settings.py file and if it's successfully imported you get your local changes applied to the configuration. Of course, settings.py is versioned and local_settings.py unversioned. I'm looking for something like that.
gnrfan
A: 

I generally add database.yml to svn:ignore and instead commit database.yml.sample.

The local will copy the database.yml.sample as database.yml and add their own values.

This way the database.yml file cannot be accidentally committed.

xzyfer