From 2541ecad01d97aa2769bca3cd9807e2f07bcecb7 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 14 Aug 2007 23:51:50 +0000 Subject: [PATCH] implement column dropping --- Changes | 1 + DBSchema.pm | 8 ++++++-- DBSchema/Column.pm | 17 +++++++++++++++++ DBSchema/Table.pm | 14 +++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index cfcb123..4f2037b 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for Perl extension DBIx::DBSchema. - More work on update schema from Slaven Rezic , 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 , thanks! (closes: CPAN#27958) - Make table dropping optional, not the default. diff --git a/DBSchema.pm b/DBSchema.pm index 6b6b1c2..f1db65d 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -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 and Mitchell Friedman Daniel Hanks 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 contributed column and table dropping, Pg +bugfixes and more. =head1 CONTRIBUTIONS diff --git a/DBSchema/Column.pm b/DBSchema/Column.pm index 5f0d7d1..d43d0b7 100644 --- a/DBSchema/Column.pm +++ b/DBSchema/Column.pm @@ -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 diff --git a/DBSchema/Table.pm b/DBSchema/Table.pm index 899fe94..16ba3a0 100644 --- a/DBSchema/Table.pm +++ b/DBSchema/Table.pm @@ -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 -- 2.11.0