[Dbix-class] Howto convert from DB to Schema

Brandon Black blblack at gmail.com
Mon Feb 6 19:14:45 CET 2006


On 2/6/06, James FitzGibbon <jfitzgibbon at primustel.ca> wrote:
> I've read over DBIx::Class::Manual::SchemaIntro, but I'm still a bit
> confused as to how to move my DB-based set of classes over to Schema.
>
> My current class hierarchy looks like this:
> [....]
>
> Am I just screwing myself trying to have the same classes work with both
> Oracle and PostgreSQL?
>

This (the situation you're facing with PK::Auto::* and using the same
schema against multiple vendors) sounds more like something we can
improve on the DBIx::Class end of things, rather than having you hack
around it like that.

> Perhaps this isn't a big concern - do most people use
> DBIx::Class::Schema::Loader and thus only have the additional classes listed
> once in their code?  A long time ago at our local PM meeting, the feeling of
> the room was to use ::Loader in development and then switch to statically
> defined classes for production (this was using CDBI).  Is that no longer
> conventional wisdom?

That wisdom still basically applies.

A Schema generated by DBIx::Class::Schema::Loader is fairly identical
in practice to a manually defined basic DBIx::Class::Schema setup, so
it's not as bad a thing as when, for instance, DBIx::Class::Loader was
giving people interfaces that were very different from
DBIx::Class::DB, and that caused some confusion and difficulty weaning
yourself off of it.  Using ::Schema::Loader initially shouldn't cause
problems for you down the road like that.

However, for any project of sufficient application and/or database
complexity, you almost definitely will want to move off of
Schema::Loader to manually defined classes at some point.  That
transition should be virtually pain-free if you start off by dumping
the Schema::Loader-generated Schema via SQLT and work from there.  If
there was anything Loader-specific in your code that wouldn't survive
the transition, it would be very easy to spot, as any such methods are
called via $schema->loader->xxx.  (And the only things there in
->loader-> space that matter are methods for getting the moniker for a
table name, basically the translation of table name
"persons_in_calgary" to the moniker "PersonsInCalgary")

-- Brandon



More information about the Dbix-class mailing list