From: Rafael Kitover <rkitover@cpan.org>
Date: Sun, 16 Jan 2011 13:53:39 +0000 (-0500)
Subject: add datetime_undef_if_invalid => 1 for MySQL date data types (RT#64820)
X-Git-Tag: 0.07003~14
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58333f16015622ba917cac66272c1f599db839c0;p=dbsrgits%2FDBIx-Class-Schema-Loader.git

add datetime_undef_if_invalid => 1 for MySQL date data types (RT#64820)
---

diff --git a/Changes b/Changes
index 72bbde4..9ac108a 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - add datetime_undef_if_invalid => 1 for MySQL date data types
+          (RT#64820)
         - added column_accessor_map option
         - Preserve relationship names when redumping and another FK is added
           (RT#62424)
diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
index 357cb75..83a9387 100644
--- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
+++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
@@ -176,6 +176,9 @@ EOF
                 delete $info->{size};
             }
         }
+        elsif ($info->{data_type} =~ /^(?:date(?:time)?|timestamp)\z/) {
+            $info->{datetime_undef_if_invalid} = 1;
+        }
 
         # Sometimes apparently there's a bug where default_value gets set to ''
         # for things that don't actually have or support that default (like ints.)
diff --git a/t/11mysql_common.t b/t/11mysql_common.t
index 045675d..e414380 100644
--- a/t/11mysql_common.t
+++ b/t/11mysql_common.t
@@ -90,10 +90,10 @@ my $tester = dbixcsl_common_tests->new(
         'fixed(3,3)'   => { data_type => 'decimal', size => [3,3] },
 
         # Date and Time Types
-        'date'        => { data_type => 'date' },
-        'datetime'    => { data_type => 'datetime' },
+        'date'        => { data_type => 'date', datetime_undef_if_invalid => 1 },
+        'datetime'    => { data_type => 'datetime', datetime_undef_if_invalid => 1 },
         'timestamp default current_timestamp'
-                      => { data_type => 'timestamp', default_value => \'current_timestamp' },
+                      => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 },
         'time'        => { data_type => 'time' },
         'year'        => { data_type => 'year' },
         'year(4)'     => { data_type => 'year' },