implement column dropping
authorivan <ivan>
Tue, 14 Aug 2007 23:51:50 +0000 (23:51 +0000)
committerivan <ivan>
Tue, 14 Aug 2007 23:51:50 +0000 (23:51 +0000)
Changes
DBSchema.pm
DBSchema/Column.pm
DBSchema/Table.pm

diff --git a/Changes b/Changes
index cfcb123..4f2037b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ Revision history for Perl extension DBIx::DBSchema.
         - More work on update schema from Slaven Rezic <srezic@cpan.org>,
           thanks!
           + implement table dropping (closes: CPAN#27936)
+          + implement column dropping (closes: CPAN#27896)
         - Fix to quiet warnings from internal use of old API from Jesse Vincent
           <jesse+cpan@fsck.com>, thanks! (closes: CPAN#27958)
         - Make table dropping optional, not the default.
index 6b6b1c2..f1db65d 100644 (file)
@@ -10,7 +10,7 @@ use DBIx::DBSchema::Column;
 use DBIx::DBSchema::ColGroup::Unique;
 use DBIx::DBSchema::ColGroup::Index;
 
-$VERSION = "0.34_02";
+$VERSION = "0.34_03";
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
@@ -498,7 +498,11 @@ Charles Shapiro <charles.shapiro@numethods.com> and Mitchell Friedman
 
 Daniel Hanks <hanksdc@about-inc.com> contributed the Oracle driver.
 
-Jesse Vincent contributed the SQLite driver.
+Jesse Vincent contributed the SQLite driver and fixes to quiet down
+internal usage of the old API.
+
+Slaven Rezic <srezic@cpan.org> contributed column and table dropping, Pg
+bugfixes and more.
 
 =head1 CONTRIBUTIONS
 
index 5f0d7d1..d43d0b7 100644 (file)
@@ -511,6 +511,23 @@ sub sql_alter_column {
   @r;
 
 }
+=item sql_drop_column [ DBH ] 
+
+Returns a list of SQL statements to drop this column from an existing table.
+
+The optional database handle or DBI data source/username/password is not yet
+used.
+
+=cut
+
+sub sql_drop_column {
+ my( $self, $dbh ) = ( shift, _dbh(@_) );
+ my $table = $self->table_name;
+ my $name = $self->name;
+ ("ALTER TABLE $table DROP COLUMN $name"); # XXX what about indexes???
+}
 
 =back
 
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