[Catalyst] DBIC::Schema [and schema::loader] from YAML

Brandon Black blblack at gmail.com
Thu Sep 28 17:35:26 CEST 2006


On 9/28/06, leonard.a.jaffe at jpmchase.com <leonard.a.jaffe at jpmchase.com>
wrote:
>
>
> Brian Cassidy wrote:
>
> > Jon Warbrick wrote:
> > > Can a Catalyst::Model::DBIC::Schema model be configured from a YAML
> > > file via Catalyst::Plugin::Config::YAML? If so, how? Apologies if it's
> in
> > > the documentation somewhere, but if so I've yet to find it...
> > >
> > in myapp.yml
> >
> > Model::MyModel:
> >   schema_class: MySchema
> >   connect_info:
> >     - dbi:blahblah
> >     - username
> >     - password
>
> While we're on the subject, lets assume that MySchema is
> 'myapp::SchemaLoader::foo.
>
> How do I make sure that my SchemaLoader can see the config when it tries
> to execute
> __PACKAGE__->connection?
>
> It isn't seeing the Model::MyModel connect_info, admonishing me for
> failing to provide
> connection info.



As with all things Perl, TIMTOWTDI.  While you *can* specify the connection
in the Schema, its generally not a great idea.

Best practice would be that myapp::SchemaLoader::foo should just contain the
"loader_options" method, and really nothing else (no connect/connection
call).  Then when the Model makes the connection using your connect_info
configuration, that's when the actual dynamic loading will happen.

Even better practice would be to use the helper in create=static mode
instead of create=dynamic, so that you're not re-scanning the table
definitions at every server start.  If you insist on maintaining your
database the old-fashioned way (or have no control over it), you can
regenerate via create=static each time there's a change in the DDL, and diff
versus the previous version to see the changes, etc.

The next step beyond that is to start maintaining your database tables using
the generated DBIC schema and the SQLT/->deploy support.  Then you won't
need Loader at all.

Another good practice is to move the Schema definitions outside of the
myapp:: Catalyst-app namespace, so that you can deploy the Schema
independantly for other tools that might need access to your database.

[maybe I should make a best practices section in the Schema::Loader pod?]

-- Brandon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060928/4ab72659/attachment.htm 


More information about the Catalyst mailing list