fix coverage testing (thanks Matthew Horsfall!)
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / DeployMethod / SQL / Translator.pm
index d7601c6..3424c01 100644 (file)
@@ -264,19 +264,20 @@ sub _split_sql_chunk {
         s/^(?:BEGIN|BEGIN TRANSACTION|COMMIT).*//mgi;
 
         # trim whitespaces
-        s/^\s+|\s+$//mg;
+        s/^\s+//gm;
+        s/\s+$//gm;
 
         # remove comments
         s/^--.*//gm;
 
         # remove blank lines
-        s/^\n//mg;
+        s/^\n//gm;
 
         # put on single line
         s/\n/ /g;
     }
 
-    return @sql;
+    return grep $_, @sql;
 }
 
 sub _run_sql {
@@ -287,6 +288,7 @@ sub _run_sql {
 
 sub _load_sandbox {
   my $_file = shift;
+  $_file = "$_file";
 
   my $_package = $_file;
   $_package =~ s/([^A-Za-z0-9_])/sprintf("_%2x", ord($1))/eg;
@@ -338,7 +340,7 @@ sub _run_sql_and_perl {
      my $sql = ($sql_to_run)?join ";\n", @$sql_to_run:'';
      FILENAME:
      for my $filename (map file($_), @files) {
-       if ($self->ignore_ddl && $filename->basename =~ /^[^_]*-auto.*\.sql$/) {
+       if ($self->ignore_ddl && $filename->basename =~ /^[^-]*-auto.*\.sql$/) {
          next FILENAME
        } elsif ($filename =~ /\.sql$/) {
           $sql .= $self->_run_sql($filename)
@@ -359,8 +361,9 @@ sub deploy {
   log_info { "deploying version $version" };
   my $sqlt_type = $self->storage->sqlt_type;
   my $sql;
+  my $sqltargs = $self->sql_translator_args;
   if ($self->ignore_ddl) {
-     $sql = $self->_sql_from_yaml({},
+     $sql = $self->_sql_from_yaml($sqltargs,
        '_ddl_protoschema_deploy_consume_filenames', $sqlt_type
      );
   }
@@ -483,10 +486,10 @@ sub _sql_from_yaml {
   my @sql;
 
   my $actual_file = $self->$from_file($version);
-  for my $yaml_filename (@{
+  for my $yaml_filename (@{(
      DlogS_trace { "generating SQL from Serialized SQL Files: $_" }
         (ref $actual_file?$actual_file:[$actual_file])
-  }) {
+  )}) {
      my $sqlt = SQL::Translator->new({
        add_drop_table          => 0,
        parser                  => 'SQL::Translator::Parser::YAML',
@@ -525,7 +528,7 @@ sub _prepare_install {
       }
     }
     open my $file, q(>), $filename;
-    print {$file} join ";\n", @$sql;
+    print {$file} join ";\n", @$sql, '';
     close $file;
   }
 }
@@ -589,7 +592,13 @@ sub prepare_deploy {
   my $self = shift;
   $self->prepare_protoschema({
       # Exclude __VERSION so that it gets installed separately
-      parser_args => { sources => [grep { $_ ne '__VERSION' } $self->schema->sources], }
+      parser_args => {
+         sources => [
+            sort { $a cmp $b }
+            grep { $_ ne '__VERSION' }
+            $self->schema->sources
+         ],
+      }
   }, '_ddl_protoschema_produce_filename');
   $self->_prepare_install({}, '_ddl_protoschema_produce_filename', '_ddl_schema_produce_filename');
 }
@@ -703,14 +712,13 @@ sub prepare_protoschema {
 
   # we do this because the code that uses this sets parser args,
   # so we just need to merge in the package
-  $sqltargs->{parser_args}{package} = $self->schema;
   my $sqlt = SQL::Translator->new({
     parser                  => 'SQL::Translator::Parser::DBIx::Class',
     producer                => 'SQL::Translator::Producer::YAML',
     %{ $sqltargs },
   });
 
-  my $yml = $sqlt->translate;
+  my $yml = $sqlt->translate(data => $self->schema);
 
   croak("Failed to translate to YAML: " . $sqlt->error)
     unless $yml;