From: ivan Date: Sun, 28 Oct 2007 12:53:17 +0000 (+0000) Subject: fix mysql NULL reverse-engineering and updating X-Git-Tag: DBIx_DBSchema_0_35~1 X-Git-Url: http://git.freeside.biz/gitweb/?p=DBIx-DBSchema.git;a=commitdiff_plain;h=3f71532c073ddb428889a4c46843cb82f5be15ad fix mysql NULL reverse-engineering and updating --- diff --git a/Changes b/Changes index f0c68ef..4ce418a 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ Revision history for Perl extension DBIx::DBSchema. - Update Column.pm, move all mysql and Pg-specific code to DBD driver callbacks - Update Table.pm, add local_options + - Fix mysql NULL reverse-engineering and updating code 0.34 Sun Aug 19 10:08:51 PDT 2007 - More work on update schema from Slaven Rezic , diff --git a/DBSchema/DBD/mysql.pm b/DBSchema/DBD/mysql.pm index a99dcf4..0bda38d 100644 --- a/DBSchema/DBD/mysql.pm +++ b/DBSchema/DBD/mysql.pm @@ -32,6 +32,7 @@ $schema = new_native DBIx::DBSchema $dbh; This module implements a MySQL-native driver for DBIx::DBSchema. =cut + use Data::Dumper; sub columns { my($proto, $dbh, $table ) = @_; @@ -40,13 +41,14 @@ sub columns { my $sth = $dbh->prepare("SHOW COLUMNS FROM $table") or die $dbh->errstr; $sth->execute or die $sth->errstr; my @r = map { + #warn Dumper($_); $_->{'Type'} =~ /^(\w+)\(?([^)]+)?\)?( \d+)?$/ or die "Illegal type: ". $_->{'Type'}. "\n"; my($type, $length) = ($1, $2); [ $_->{'Field'}, $type, - $_->{'Null'}, + ( $_->{'Null'} =~ /^YES$/i ? 'NULL' : '' ), $length, $_->{'Default'}, $_->{'Extra'} @@ -130,6 +132,28 @@ sub column_callback { } +sub alter_column_callback { + my( $proto, $dbh, $table, $old_column, $new_column ) = @_; + my $old_name = $old_column->name; + my $new_def = $new_column->line($dbh); + +# this would have been nice, but it appears to be doing too much... + +# return {} if $old_column->line($dbh) eq $new_column->line($dbh); +# +# #{ 'sql_alter' => +# { 'sql_alter_null' => +# "ALTER TABLE $table CHANGE $old_name $new_def", +# }; + + return {} if $old_column->null eq $new_column->null; + { 'sql_alter_null' => + "ALTER TABLE $table MODIFY $new_def", + }; + + +} + =head1 AUTHOR Ivan Kohler