implement column dropping
[DBIx-DBSchema.git] / DBSchema / Table.pm
index 899fe94..16ba3a0 100644 (file)
@@ -609,7 +609,7 @@ sub sql_alter_table {
   my $tempnum = 1;
 
   ###
-  # columns
+  # columns (add/alter)
   ###
 
   foreach my $column ( $new->columns ) {
@@ -690,6 +690,18 @@ sub sql_alter_table {
     warn "creating new index $table.$new\n" if $DEBUG > 1;
     push @r, $new_indices{$new}->sql_create_index($table);
   }
+
+  ###
+  # columns (drop)
+  ###
+
+  foreach my $column ( grep !$new->column($_), $self->columns ) {
+
+    warn "column $table.$column should be dropped.\n" if $DEBUG;
+
+    push @r, $self->column($column)->sql_drop_column( $dbh );
+
+  }
   
   ###
   # return the statements