Re: [Catalyst] One App, multiple databases

2008-11-19 Thread Chris Carline
On Wed, Nov 19, 2008 at 10:53 PM, Jose Luis Martinez
<[EMAIL PROTECTED]> wrote:
> Basically we giving multi-tentant capability to our app (which was ported
> from some old CGIs). The CGIs where setup to load config files based on the
> REMOTE_USER, so we gave each user a separate DB just by changing the connect
> string. Now in Catayst we want the same effect ;), as sharing one database
> between all users is a step we don't want to take (for the moment).

I've achieved something similar to this by connecting to the
user-specific database where appropriate via an effective model-like
(non cat) module in the Root/auto portion of the application.

This works well-enough for my purposes, but you might want to call out
to a dedicated service if you want to achieve better persistence than
this would otherwise afford.

Chris

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] One App, multiple databases

2008-11-19 Thread Jose Luis Martinez

Mesdaq, Ali escribió:
Are these db's exact copies as far as schema from each other? Or is it different tables and structure as well? 


Reason I am asking is because if its exactly the same and all your queries work 
the same and your logic works the same as well and the only difference is if 
user1 is connected then connect to one schema and if user2 is connected connect 
to another schema you might be able to more cleanly determine the db in your 
controller code. You would also then create a model for each user. This would 
give you granular control over if the user db's ever move or if you need to 
configure specific connection data per users db like different user accounts 
and passwords etc.

So instead of something like:
$c->model('DB::Blah')->all


Yes, they are exactly the same. But I'm not really all that keen on 
creating one model per user (because the users would be created and 
deleted), and that would mean that will have to be added and deleted, 
and app servers restarted.



But I think knowing a little more about your exact situation might help 
understand the issue more.


Basically we giving multi-tentant capability to our app (which was 
ported from some old CGIs). The CGIs where setup to load config files 
based on the REMOTE_USER, so we gave each user a separate DB just by 
changing the connect string. Now in Catayst we want the same effect ;), 
as sharing one database between all users is a step we don't want to 
take (for the moment).


Hope that explains a bit more.

Thanks,

Jose Luis Martinez
[EMAIL PROTECTED]

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: One App, multiple databases

2008-11-19 Thread Jose Luis Martinez

kevin montuori escribió:

i'm wondering why you wouldn't have two models with different connection
information but that use the same schema?  


Because I wouldn't want application code touched for every user created 
or deleted... Every user will have a new db, and user creation should be 
automatable. Adding new model classes would imply restarts for every 
user added / deleted.



i might be mistaken, but it
seems that tying a user to a physical database circumvents some of the
abstraction MVC provides.


Exact same schema for every user. I think It's really the same level of 
abstraction. The app only uses one database per user. No info from 
databases of other users is needed.


Regards,

Jose Luis Martinez
[EMAIL PROTECTED]

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] need to patch Test::WWW::Mechanize::Catalyst

2008-11-19 Thread Jason Gottshall

Ash Berlin wrote:


On 19 Nov 2008, at 20:21, Jason Gottshall wrote:


My recent patch to 5.80 trunk (svn rev 8612) enables the setting of a
default virtual hostname via import:

 use Catalyst::Test 'MyApp', { default_host => 'virtual.com' };

Based on my reading of the Test::WWW::Mech::Catalyst source, some minor
changes would need to be made there in order to use the same semantics
with Mech::Cat. Should I try to patch this myself, or is there a 
maintainer out there who can make it happen?


The maintainer is Léon Brocard. But send a patch and make his life 
easier :)


Patch attached. I hope it really was as easy as it looked. Did I miss 
anything?


--
Jason Gottshall
[EMAIL PROTECTED]

--- orig/Test/WWW/Mechanize/Catalyst.pm 2008-10-27 09:50:54.0 -0400
+++ new/Test/WWW/Mechanize/Catalyst.pm  2008-11-19 15:58:40.0 -0500
@@ -98,8 +98,10 @@
 package Test::WWW::Mechanize::Catalyst::Aux;

 sub import {
-my ( $class, $name ) = @_;
-eval "use Catalyst::Test '$name'";
+eval {
+require Catalyst::Test;
+Catalyst::Test::import(@_);
+};
 warn $@ if $@;
 }

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] need to patch Test::WWW::Mechanize::Catalyst

2008-11-19 Thread Ash Berlin


On 19 Nov 2008, at 20:21, Jason Gottshall wrote:


My recent patch to 5.80 trunk (svn rev 8612) enables the setting of a
default virtual hostname via import:

 use Catalyst::Test 'MyApp', { default_host => 'virtual.com' };

Based on my reading of the Test::WWW::Mech::Catalyst source, some  
minor

changes would need to be made there in order to use the same semantics
with Mech::Cat. Should I try to patch this myself, or is there a  
maintainer out there who can make it happen?


Thanks!
Jason

--
Jason Gottshall
[EMAIL PROTECTED]



The maintainer is Léon Brocard. But send a patch and make his life  
easier :)

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] need to patch Test::WWW::Mechanize::Catalyst

2008-11-19 Thread Jason Gottshall

My recent patch to 5.80 trunk (svn rev 8612) enables the setting of a
default virtual hostname via import:

  use Catalyst::Test 'MyApp', { default_host => 'virtual.com' };

Based on my reading of the Test::WWW::Mech::Catalyst source, some minor
changes would need to be made there in order to use the same semantics
with Mech::Cat. Should I try to patch this myself, or is there a 
maintainer out there who can make it happen?


Thanks!
Jason

--
Jason Gottshall
[EMAIL PROTECTED]




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] One App, multiple databases

2008-11-19 Thread Mesdaq, Ali
Are these db's exact copies as far as schema from each other? Or is it 
different tables and structure as well? 

Reason I am asking is because if its exactly the same and all your queries work 
the same and your logic works the same as well and the only difference is if 
user1 is connected then connect to one schema and if user2 is connected connect 
to another schema you might be able to more cleanly determine the db in your 
controller code. You would also then create a model for each user. This would 
give you granular control over if the user db's ever move or if you need to 
configure specific connection data per users db like different user accounts 
and passwords etc.

So instead of something like:
$c->model('DB::Blah')->all

You could do:
$c->model("$user:Blah")->all

But I think knowing a little more about your exact situation might help 
understand the issue more.

Thanks,
--
Ali Mesdaq (CISSP, GIAC-GREM)
Sr. Security Researcher
Websense Security Labs
http://www.WebsenseSecurityLabs.com
--


-Original Message-
From: Jose Luis Martinez [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 19, 2008 9:54 AM
To: The elegant MVC web framework
Subject: [Catalyst] One App, multiple databases

Hello,

This question has been asked a couple of times on the list, and I have 
found yet another solution to it, but I would like to hear if maybe I'm 
doing something wrong, or I will suffer serious pain by doing it my way :)

We have an app that will connect to one database or another depending on 
the logged in user.

My solution:

package App::Model::DB;

use strict;
use base 'Catalyst::Model::DBIC::Schema';
...
sub ACCEPT_CONTEXT {
 my ($self, $c) = @_;

 my $user_db = $c->lookup_the_users_db();
 $self->config->{'connect_info'}->[0] =~ s/#DATABASE#/$user_db/;
 $self->schema->connection(@{$self->config->{'connect_info'}});

 return $self;
}


1;

I've done the same with Catalyst::Model::DBI:

package App::Model::AnotherDB;

use strict;
use base 'Catalyst::Model::DBI';

sub ACCEPT_CONTEXT {
 my ($self, $c) = @_;

 my $user_db = $c->lookup_the_users_db();
 $self->{'dsn'} =~ s/#DATABASE#/$user_db/;

 return $self;
}

1;

And the two seem to be working OK, but I'm worried about what will 
happen when we fire it up in a FastCGI environment (I suspect the 
connection to  user1's database will be kept live, and the next user 
will get the connection to it). Am I right? Any pointers?

Does this way of using the models trigger any warning lights to Catalyst 
gurus?

Thanks in advance,

Jose Luis Martinez
[EMAIL PROTECTED]

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


 Protected by Websense Hosted Email Security -- www.websense.com 

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Re: One App, multiple databases

2008-11-19 Thread kevin montuori
> "JLM" == Jose Luis Martinez <[EMAIL PROTECTED]> writes:

 JLM> We have an app that will connect to one database or another
 JLM> depending on the logged in user.

i'm wondering why you wouldn't have two models with different connection
information but that use the same schema?  i might be mistaken, but it
seems that tying a user to a physical database circumvents some of the
abstraction MVC provides.

k.

-- 
kevin montuori
[EMAIL PROTECTED]

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] One App, multiple databases

2008-11-19 Thread Jose Luis Martinez

Hello,

This question has been asked a couple of times on the list, and I have 
found yet another solution to it, but I would like to hear if maybe I'm 
doing something wrong, or I will suffer serious pain by doing it my way :)


We have an app that will connect to one database or another depending on 
the logged in user.


My solution:

package App::Model::DB;

use strict;
use base 'Catalyst::Model::DBIC::Schema';
...
sub ACCEPT_CONTEXT {
my ($self, $c) = @_;

my $user_db = $c->lookup_the_users_db();
$self->config->{'connect_info'}->[0] =~ s/#DATABASE#/$user_db/;
$self->schema->connection(@{$self->config->{'connect_info'}});

return $self;
}


1;

I've done the same with Catalyst::Model::DBI:

package App::Model::AnotherDB;

use strict;
use base 'Catalyst::Model::DBI';

sub ACCEPT_CONTEXT {
my ($self, $c) = @_;

my $user_db = $c->lookup_the_users_db();
$self->{'dsn'} =~ s/#DATABASE#/$user_db/;

return $self;
}

1;

And the two seem to be working OK, but I'm worried about what will 
happen when we fire it up in a FastCGI environment (I suspect the 
connection to  user1's database will be kept live, and the next user 
will get the connection to it). Am I right? Any pointers?


Does this way of using the models trigger any warning lights to Catalyst 
gurus?


Thanks in advance,

Jose Luis Martinez
[EMAIL PROTECTED]

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/