[Dbix-class] connecting to different environments

Alan Humphrey alan.humphrey at comcast.net
Sun Sep 11 16:37:51 GMT 2011


Hi -

I'm wondering how people are handling connecting to different databases,
e.g. dev vs. test vs. production.  Is there a technique that's considered
"best practice"?


Configuration files are good things. Just swap in the right config
file for a given environment.

 

Yes, this isn't really DBIC specific, but I wrote a config system that
merges together different config files into a final hash that can be used by
a number of tools -- including cron jobs and our Catalyst-based apps.

 

We set an operation mode (e.g. production, staging, testing, dev) in the
environment and the config system merges config.yml, conf/$mode.yml,
/etc/$app/$mode.yml, and $HOME/local_$app.yml.

 

That way, config.yml has the bulk of the config, then something like
production.yml just changes the few settings needed for production.  We can
inherit, too.  For example, staging.yml can say "inherit: production.yml"
and then staging can override setting set for production.

 

The /etc/ fies is to allow the site operators to override config, if needed,
and the $HOME config allows developers to override config on their
development machine.

 

It's actually a bit more convoluted than that, because each config file can
have sections specific to a given operating mode.

 

 

In a system like this (or in any system using config files) what does your
connect statement look like?  I'm imagining something like:

 

my $schema = MyApp::Schema->connect();

 

or

 

my $schema = MyApp::Schema->connect( $env_override );

 

where the logic in connect takes care of dealing with the config file and
does other safety checks (e.g. no access to production data from a
non-production machine).

 

The docs say to overload connection to change the behavior of connect.  Is
that what people are doing?

 

Thanks again, this discussion is very helpful.

 

-          Alan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110911/2b1534c2/attachment.htm


More information about the DBIx-Class mailing list