[DBIx-Class] Using multiple databases / schemas in DBIC and Catalyst

Matt S Trout dbix-class at trout.me.uk
Mon Jul 21 22:43:58 BST 2008


On Sun, Jul 20, 2008 at 10:00:46PM +0530, jagdish eashwar wrote:
> Hi Matt,
> 
> I wanted to use more than one database / schema in a web application using
> Catalyst and DBIC.  In this connection, I had asked a question on the
> Catalyst mailing list because I was not able to set up relationships between
> tables in two separate Mysql schemas. You replied that it was possible if
> separate DBIC namespaces were set up, and suggested that for further
> discussion, I should ask the question on the DBIx mailing list.
> 
> To recap, I am working on two small Catalyst web applications.  One deals
> with the leave particulars of the employees  and the other with the hardware
> issued to them. Both these applications use some common information about
> the employees. At present, I am maintaining these 'common' tables in the
> schemas of both the applications. I would like to put the 'common' tables in
> a third schema and make the two applications access them from there.

Ok.

MyBaseSchema should load classes for the common database using
->table('common.foo')

MyOneSchema should use base MyBaseSchema and load classes for the specific
db.

That'll give you a single DBIC schema that covers both databases. Then rels
will work.

A DBIx::Class::Schema subclass does -not- have to correspond to a single
database/schema on the db server end. If you need cross-rels, the classes
all need to be registered within a single DBIC schema, but there's no
reason the tables can't live in more than one mysql db or pg schema or
whatever.

That's the important difference I've been trying to explain - make more
sense now?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list