drop table patch from Slaven, closes: CPAN#27936
authorivan <ivan>
Thu, 5 Jul 2007 18:38:56 +0000 (18:38 +0000)
committerivan <ivan>
Thu, 5 Jul 2007 18:38:56 +0000 (18:38 +0000)
Changes
DBSchema.pm
DBSchema/DBD.pm
DBSchema/Table.pm

diff --git a/Changes b/Changes
index ff6c70c..439cbb9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
 Revision history for Perl extension DBIx::DBSchema.
 
+0.34 unreleased
+        - More work on update schema from Slaven Rezic <srezic@cpan.org>,
+          thanks!
+          + implement table dropping (closes: CPAN#27936)
+
 0.33 Thu Jun 28 18:46:15 PDT 2007
         - Overhaul of index representation: indices (both normal and unique)
           now have names and are DBIx::DBSchema::Index objects
index 95ac630..b821d16 100644 (file)
@@ -4,14 +4,14 @@ use strict;
 use vars qw($VERSION $DEBUG $errstr);
 use Storable;
 use DBIx::DBSchema::_util qw(_load_driver _dbh);
-use DBIx::DBSchema::Table 0.04;
+use DBIx::DBSchema::Table 0.05;
 use DBIx::DBSchema::Index;
 use DBIx::DBSchema::Column;
 use DBIx::DBSchema::ColGroup::Unique;
 use DBIx::DBSchema::ColGroup::Index;
 
-$VERSION = "0.33";
-#$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
+$VERSION = "0.34_01";
+$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
 
@@ -289,7 +289,17 @@ sub sql_update_schema {
   
   }
 
-  # should eventually drop tables not in $new
+  # drop tables not in $new
+  foreach my $table ( $self->tables ) {
+
+    if ( !$new->table($table) ) {
+
+      warn "table $table should be dropped.\n" if $DEBUG;
+
+      push @r,
+       $self->table($table)->sql_drop_table( $dbh );
+    }
+  }
 
   warn join("\n", @r). "\n"
     if $DEBUG > 1;
index 329366a..47f884e 100644 (file)
@@ -107,31 +107,31 @@ sub indices {
   my $unique_hr = $proto->unique( @param );
   my $index_hr  = $proto->index(  @param );
 
-  my $gratuitous_hashref_to_force_scalar_context =
-  {
-
-    (
-      map {
-            $_ => { 'name'    => $_,
-                    'unique'  => 1,
-                    'columns' => $unique_hr->{$_},
-                  },
-          }
-          keys %$unique_hr
-    ),
-
-    (
-      map {
-            $_ => { 'name'    => $_,
-                    'unique'  => 0,
-                    'columns' => $index_hr->{$_},
-                  },
-          }
-          keys %$index_hr
-    ),
-
-  };
-
+  scalar(
+    {
+  
+      (
+        map {
+              $_ => { 'name'    => $_,
+                      'unique'  => 1,
+                      'columns' => $unique_hr->{$_},
+                    },
+            }
+            keys %$unique_hr
+      ),
+  
+      (
+        map {
+              $_ => { 'name'    => $_,
+                      'unique'  => 0,
+                      'columns' => $index_hr->{$_},
+                    },
+            }
+            keys %$index_hr
+      ),
+  
+    }
+  );
 }
 
 =item default_db_catalog
index a51acc8..b19e7ef 100644 (file)
@@ -10,7 +10,7 @@ use DBIx::DBSchema::Index;
 use DBIx::DBSchema::ColGroup::Unique;
 use DBIx::DBSchema::ColGroup::Index;
 
-$VERSION = '0.04';
+$VERSION = '0.05';
 $DEBUG = 0;
 
 =head1 NAME
@@ -683,6 +683,14 @@ sub sql_alter_table {
 
 }
 
+sub sql_drop_table {
+  my( $self, $dbh ) = ( shift, _dbh(@_) );
+
+  my $name = $self->name;
+
+  ("DROP TABLE $name");
+}
+
 sub _null_sth {
   my($dbh, $table) = @_;
   my $sth = $dbh->prepare("SELECT * FROM $table WHERE 1=0")