[Dbix-class] Patch for SQL::Translator::Parser::DBIx::Class

Sebastian Willert willert at gmail.com
Sun Jun 25 18:35:35 CEST 2006


Hi all,

after some late-night discussion with castaway about
DBIC::Schema->deploy() we noticed that
SQL::Translator::Parser::DBIx::Class tries to query the connected
database. This shouldn't be done IMO because this might change the info
provided in the schema and might not be stable between different
underlying RDBMs. 

This are the reasons why I've produced the patch below, the changes
should be self-explainatory. The patch has been tested on the
command-line, using the programmatic interface of SQLT and using
DBIC::Schema->deploy() but could need some additional testing with more
complex schema then I have readily available.

Cheers,
  Sebastian

--

Index: lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- lib/SQL/Translator/Parser/DBIx/Class.pm     (revision 2043)
+++ lib/SQL/Translator/Parser/DBIx/Class.pm     (working copy)
@@ -30,13 +30,19 @@
     my $args        = $tr->parser_args;
     my $dbixschema  = $args->{'DBIx::Schema'} || $data;
     $dbixschema   ||= $args->{'package'};
-    
+
+    # operating on a connected schema instance will yield additional
+    # info about data definitions. This is uncalled for: if the user
+    # wanted this additional info she would have used an SQL parser.
+    $dbixschema = ref( $dbixschema ) || $dbixschema ;
     die 'No DBIx::Schema' unless ($dbixschema);
-    if (!ref $dbixschema) {
-      eval "use $dbixschema;";
-      die "Can't load $dbixschema ($@)" if($@);
-    }
 
+    # ensure that the schema is loaded and a proper subclass of
+    # DBIx::Schema
+    eval "require $dbixschema";
+    die( "'$dbixschema' is no DBIx::Class::Schema subclass" )
+      unless eval{ $dbixschema->isa( qw/DBIx::Class::Schema/ ) };
+
     my $schema      = $tr->schema;
     my $table_no    = 0;
 





More information about the Dbix-class mailing list