[Dbix-class] Howto convert from DB to Schema

James FitzGibbon jfitzgibbon at primustel.ca
Mon Feb 6 17:27:59 CET 2006


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:

SPE::DA is-a DBIx::Class and loads the 'Core' and 'DB' components at compile
time.  At runtime, it loads PK::Auto::Oracle or PK::Auto::Pg depending on
the DBD in use.  This is shared among multiple projects.  From a discussion
here about a month ago, it is important that the PK::Auto:: component be
more to the left in the inheritance tree than Core and DB in order for
->insert to be overridden properly.

SPE::DA::DCH is for a specific project and is-a SPE::DA.  It has about 10
subclasses (one for each table) in one file, statically defined.

Now, for me to convert to Schema, the docs seem to suggest that there is no
longer a need for SPE::DA.  In the new world, SPE::DA::DCH is-a
DBIx::Class::Schema and uses ->load_classes() to load all the statically
defined subclasses, each of which is-a SPE::DA::DCH.

Each of the subclasses needs to load the Core component.  Now I have to load
the proper PK::Auto component in each of the subclasses of my schema.  I
guess that the best place for this is a method in SPE::DA::DCH, but now I
have to have an initialization subroutine in each of my subclasses and this
in SPE::DA::DCH's initialization:

    {
        no strict 'refs';
        for my $suffix( keys %{$class.'::'} ) {
            next unless( $suffix =~ m/^(.+)::$/ );
            my $subclass = "${class}::" . $1;
            if( UNIVERSAL::isa($subclass, 'UNIVERSAL') &&
$subclass->can('setup') ) {
                $subclass->setup;
            }
        }
    }

(yes, I know that should probably be done using ->sources)

Am I just screwing myself trying to have the same classes work with both
Oracle and PostgreSQL?

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?

Is there a concise conversion document I can look at, or should I plod
through and try to create one in the process?

Thanks

-- 
j.
 
James FitzGibbon
Systems Developer, Primus Telecommunications Canada Inc.
416.644.6111

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.2/251 - Release Date: 2/4/2006
 



-- 
----------------------------------------------------------------------------
This electronic message contains information from Primus Telecommunications
Canada Inc. ("PRIMUS") , which may be legally privileged and confidential.
The information is intended to be for the use of the individual(s) or entity
named above. If you are not the intended recipient, be aware that any
disclosure, copying, distribution or use of the contents of this information
is prohibited. If you have received this electronic message in error, please
notify us by telephone or e-mail (to the number or address above)
immediately. Any views, opinions or advice expressed in this electronic
message are not necessarily the views, opinions or advice of PRIMUS.
It is the responsibility of the recipient to ensure that
any attachments are virus free and PRIMUS bears no responsibility
for any loss or damage arising in any way from the use
thereof.The term "PRIMUS" includes its affiliates.
----------------------------------------------------------------------------
Pour la version en français de ce message, veuillez voir
 http://www.primustel.ca/fr/legal/cs.htm
----------------------------------------------------------------------------




More information about the Dbix-class mailing list