Subject: | don't force discovering schema from database |
First of all : nice plugin.
The issue : The plugin insists on using make_schema_at(), to rediscover
the schema from the database each time. It's good in some case, but in
other cases (like mine), I have already generated the DBIx Classes
files. So I'd like the plugin to just connect, and not try to
discoverthe chema fomr the DB.
I propose a trivial patch, that adds an option in the config file, to
specify if the plugin should discover the schema from the database or not.
You may want to do the opposite of the patch, so that the schema is
discovered by default
Subject: | discover_schema.patch |
--- DBIC.pm.old 2010-09-07 11:00:26.000000000 +0200
+++ DBIC.pm 2010-09-07 11:35:51.000000000 +0200
@@ -23,13 +23,20 @@
push @dsn, $cfg->{$keyword}->{dsn} if $cfg->{$keyword}->{dsn};
push @dsn, $cfg->{$keyword}->{user} if $cfg->{$keyword}->{user};
push @dsn, $cfg->{$keyword}->{pass} if $cfg->{$keyword}->{pass};
-
- make_schema_at(
- $cfg->{$keyword}->{pckg},
- {},
- [ @dsn ],
- );
-
+
+ if ($cfg->{$keyword}->{discover_schema}) {
+ make_schema_at(
+ $cfg->{$keyword}->{pckg},
+ {},
+ [ @dsn ],
+ );
+ } else {
+ my $path = $cfg->{$keyword}->{pckg};
+ $path =~ s!::|'!/!g;
+ $path .= '.pm';
+ require $path;
+ }
+
push @dsn, $cfg->{$keyword}->{options} if $cfg->{$keyword}->{options};
my $package = $cfg->{$keyword}->{pckg};
@@ -58,6 +65,7 @@
DBIC:
foo:
pckg: "Foo-Bar"
+ discover_schema: 1
dsn: "dbi:mysql:db_foo"
user: "root"
pass: "****"
@@ -101,6 +109,7 @@
DBIC:
foo:
pckg: "Foo"
+ discover_schema: 1
dsn: "dbi:mysql:db_foo"
user: "root"
pass: "****"
@@ -117,14 +126,21 @@
Each database configuration *must* have a dsn and pckg option. The dsn option
should be the L<DBI> driver connection string less the optional user/pass and
arguments options. The pckg option should be a proper Perl package name that
-Dancer::Plugin::DBIC will use as a DBIx::Class schema class. Optionally a database
-configuation may have user, pass and options paramters which are appended to the
-dsn in list form, i.e. dbi:SQLite:dbname=./foo.db, $user, $pass, $options.
+Dancer::Plugin::DBIC will use as a DBIx::Class schema class. The
+discover_schema should be a boolean. If true, the schema will be created on the
+fly from the database. If not, the plugin will assume that the schema classes
+have already been created and are in @INC. Optionally a database configuation
+may have user, pass and options paramters which are appended to the dsn in list
+form, i.e. dbi:SQLite:dbname=./foo.db, $user, $pass, $options.
=head1 AUTHOR
Al Newkirk <awncorp@cpan.org>
+=head1 CONTRIBUTOR
+
+Damien Krotkine <dams@cpan.org>
+
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by awncorp.