[Bast-commits] r4012 - DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage

ash at dev.catalyst.perl.org ash at dev.catalyst.perl.org
Fri Feb 1 19:33:00 GMT 2008


Author: ash
Date: 2008-02-01 19:33:00 +0000 (Fri, 01 Feb 2008)
New Revision: 4012

Modified:
   DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm
Log:
Fallback to SQL->SQL to diff for old producers

Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm	2008-02-01 18:49:44 UTC (rev 4011)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm	2008-02-01 19:33:00 UTC (rev 4012)
@@ -1380,10 +1380,17 @@
         next;
       }
 
+      my $difffile = $schema->ddl_filename($db, $dir, $version, $preversion);
+      print STDERR "Diff: $difffile: $db, $dir, $version, $preversion \n";
+      if(-e $difffile)
+      {
+        warn("$difffile already exists, skipping");
+        next;
+      }
+
       my $source_schema;
       {
         my $t = SQL::Translator->new;
-        $t->parser_args(no_default_sizes => 1);
         $t->debug( 0 );
         $t->trace( 0 );
         $t->parser( $db )                       or die $t->error;
@@ -1394,17 +1401,26 @@
         }
       }
 
+      # The "new" style of producers have sane normalization and can support 
+      # diffing a SQL file against a DBIC->SQLT schema. Old style ones don't
+      # And we have to diff parsed SQL against parsed SQL.
+      my $dest_schema = $sqlt_schema;
+
+      unless ( "SQL::Translator::Producers::$db"->can('preprocess_schema') ) {
+        my $t = SQL::Translator->new;
+        $t->debug( 0 );
+        $t->trace( 0 );
+        $t->parser( $db )                    or die $t->error;
+        my $out = $t->translate( $filename ) or die $t->error;
+        $dest_schema = $t->schema;
+        $dest_schema->name( $filename )
+          unless $dest_schema->name;
+      }
+
       my $diff = SQL::Translator::Diff::schema_diff($source_schema, $db,
-                                                    $sqlt_schema,   $db,
+                                                    $dest_schema,   $db,
                                                     {}
                                                    );
-      my $difffile = $schema->ddl_filename($db, $dir, $version, $preversion);
-      print STDERR "Diff: $difffile: $db, $dir, $version, $preversion \n";
-      if(-e $difffile)
-      {
-        warn("$difffile already exists, skipping");
-        next;
-      }
       if(!open $file, ">$difffile")
       { 
         $self->throw_exception("Can't write to $difffile ($!)");




More information about the Bast-commits mailing list