Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am new to using Catalyst but I have created a few applications already in it. I am making a PostgreSQL database where each user is going to be inside their own schema. Such as "User_1". Each schema is going to have tables that are 100% the same, just the schema name changes depending on the user.

Is there any way to do this with DBIC? I know I can call DBI object directly but would prefer to use DBIC since its already there. Otherwise I'd have to create my own module.

Thanks in advanced.

Replies are listed 'Best First'.
Re: Catalyst On the fly Dynamic Schema
by roboticus (Chancellor) on Mar 16, 2012 at 12:38 UTC

    Give each user their own login, and use the appropriate credentials when connecting. Then you won't have to specify the schema anywhere.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Catalyst On the fly Dynamic Schema
by Your Mother (Archbishop) on Mar 16, 2012 at 13:49 UTC

    roboticus is exactly right. If your tables are identical, you can use the same DBIC schema/model for every account, just supplying the correct connection credentials to get the right DB. Dynamic schemata are quite limiting (no many_to_many auto-discovery) and a performance hit. Per user connections are possible but not the default so you'll have to hit the docs and maybe the mailing list. I've never done it or I'd give a link/example.

    Sidenote: DBIC (DBIx::Class) is not Catalyst and does not ship with Catalyst and Catalyst doesn't tie you to any DB or model at all.

    Update: strangely enough I came across this today in looking for something unrelated. Though I've never used it, it looks like what you want if you're running DBIC in Cat: Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema.

Re: Catalyst On the fly Dynamic Schema
by erix (Prior) on Mar 17, 2012 at 23:47 UTC

    I can't comment on catalyst or DBIC, but perhaps you're better off giving each user a separate postgres database (inside a postgres cluster)?

    (But I might misunderstand; the terms 'database' and 'schema' (and 'cluster', for that matter) have more than one meaning, and different meanings in different DBMS'en.)