- mysql: when reverse engineering, transform a default of
[DBIx-DBSchema.git] / DBSchema / DBD / mysql.pm
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( {} ) };