deploy debugging and drop table statements
Jess Robinson [Sat, 11 Mar 2006 23:09:06 +0000 (23:09 +0000)]
Changes
lib/DBIx/Class/Storage/DBI.pm

diff --git a/Changes b/Changes
index 835055f..0b11f96 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for DBIx::Class
 
+0.05990_03
+        - deploy now adds drop statements before creates
+        - deploy outputs debugging statements if DBIX_CLASS_STORAGE_DBI_DEBUG is set
+
 0.05990_02 2006-03-10 13:31:37
         - remove test dep on YAML
         - additional speed tweaks for C3
index 03f3a6c..f6e682d 100644 (file)
@@ -551,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);
 }
@@ -559,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 $_";
   } 
 }