drop table patch from Slaven, closes: CPAN#27936
[DBIx-DBSchema.git] / DBSchema.pm
index 12eda6d..b821d16 100644 (file)
@@ -4,13 +4,13 @@ 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_01";
+$VERSION = "0.34_01";
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
@@ -289,10 +289,20 @@ 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;
+    if $DEBUG > 1;
 
   @r;
   
@@ -500,13 +510,6 @@ or deal with deleted or modified columns yet.
 
 Need to port and test with additional databases
 
-On schema updates, index changes are not as efficent as they could be,
-especially with large data sets.  Specifically, we don't currently recognize
-existing indices with different/"wrong" names that we could use "ALTER INDEX
-name RENAME TO new_name" on, and instead drop the "wrongly named" index and
-re-build a new one.  Since these are indices and not columns, its not a huge
-deal, everything turns out right in the end, though inefficient.
-
 Each DBIx::DBSchema object should have a name which corresponds to its name
 within the SQL database engine (DBI data source).