- mysql: when reverse engineering, transform a default of
authorivan <ivan>
Sat, 27 Mar 2010 03:32:17 +0000 (03:32 +0000)
committerivan <ivan>
Sat, 27 Mar 2010 03:32:17 +0000 (03:32 +0000)
  CURRENT_TIMESTAMP into the more common NOW()
- 0.39

Changes
DBSchema.pm
DBSchema/Column.pm
DBSchema/DBD/mysql.pm

diff --git a/Changes b/Changes
index eae6f74..f4d33e1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,9 @@
 Revision history for Perl extension DBIx::DBSchema.
 
-0.39 unreleased
-        - MySQL TEXT->LONGTEXT
+0.39 Fri Mar 26 20:24:58 PDT 2010
+        - mysql: TEXT->LONGTEXT
+        - mysql: when reverse engineering, transform a default of
+          CURRENT_TIMESTAMP into the more common NOW()
 
 0.38 Thu Jan 14 15:26:13 PST 2010
         - Bump version number for ->quoted_default availability & default
index 59cd147..a778cf0 100644 (file)
@@ -10,7 +10,7 @@ use DBIx::DBSchema::Column;
 use DBIx::DBSchema::ColGroup::Unique;
 use DBIx::DBSchema::ColGroup::Index;
 
-$VERSION = "0.39_01";
+$VERSION = "0.39";
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
index 1f0c016..f10d43a 100644 (file)
@@ -461,7 +461,12 @@ sub sql_alter_column {
     # change default
     my $old_default = $self->quoted_default($dbh);
     my $new_default = $new->quoted_default($dbh);
-    if ( $old_default ne $new_default ) {
+    if ( $old_default ne $new_default
+         && ( uc($old_default) ne 'NOW()' || uc($new_default) ne 'NOW()' )
+       )
+    {
+
+      #warn "old default: $old_default / new default: $new_default\n";
 
       my $alter = "ALTER TABLE $table ALTER COLUMN $name";
 
index 925e15a..148d215 100644 (file)
@@ -46,12 +46,18 @@ sub columns {
     $_->{'Type'} =~ /^(\w+)\(?([^)]+)?\)?( \d+)?$/
       or die "Illegal type: ". $_->{'Type'}. "\n";
     my($type, $length) = ($1, $2);
+
+    my $default = $_->{'Default'};
+    $default = '' unless defined($default);
+    $default = \0 if $default eq '0';
+    $default = \'NOW()' if uc($default) eq 'CURRENT_TIMESTAMP';
+
     [
       $_->{'Field'},
       $type,
       ( $_->{'Null'} =~ /^YES$/i ? 'NULL' : '' ),
       $length,
-      $_->{'Default'},
+      $default,
       $_->{'Extra'}
     ]
   } @{ $sth->fetchall_arrayref( {} ) };