deploy debugging and drop table statements
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI.pm
index e733b53..f6e682d 100644 (file)
@@ -68,6 +68,8 @@ sub _order_by {
     if (defined $_[0]->{order_by}) {
       $ret .= $self->SUPER::_order_by($_[0]->{order_by});
     }
+  } elsif(ref $_[0] eq 'SCALAR') {
+    $ret = $self->_sqlcase(' order by ').${ $_[0] };
   } else {
     $ret = $self->SUPER::_order_by(@_);
   }
@@ -549,7 +551,23 @@ sub deployment_statements {
   $self->throw_exception($@) if $@; 
   eval "use SQL::Translator::Producer::${type};";
   $self->throw_exception($@) if $@;
-  my $tr = SQL::Translator->new();
+  my $tr = SQL::Translator->new(
+      # Print debug info
+      debug               => 1,
+      # Print Parse::RecDescent trace
+      trace               => 0,
+      # Don't include comments in output
+      no_comments         => 1,
+      # Print name mutations, conflicts
+      show_warnings       => 0,
+      # Add "drop table" statements
+      add_drop_table      => 1,
+      # Validate schema object
+      validate            => 1,
+      # Make all table names CAPS in producers which support this option
+      format_table_name   => sub {my $tablename = shift; return uc($tablename)},
+  );
+
   SQL::Translator::Parser::DBIx::Class::parse( $tr, $schema );
   return "SQL::Translator::Producer::${type}"->can('produce')->($tr);
 }
@@ -557,6 +575,7 @@ sub deployment_statements {
 sub deploy {
   my ($self, $schema, $type) = @_;
   foreach(split(";\n", $self->deployment_statements($schema, $type))) {
+      $self->debugfh->print("$_\n") if $self->debug;
          $self->dbh->do($_) or warn "SQL was:\n $_";
   } 
 }