From: Rafael Kitover Date: Tue, 6 Sep 2011 08:16:11 +0000 (-0400) Subject: fix multiple DEFAULT NULLs X-Git-Tag: 0.07011~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=87a43db11142bab84c1ddc7c2ab7a8e08437a63a;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix multiple DEFAULT NULLs $info->{default_value} = \'null' is unsafe because Data::Dump optimizes refs to constants, so we must make sure to use: my $null = 'null'; $info->{default_value} = \$null; for all scalar refs in the dump. --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm index ecfd87b..6518601 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm @@ -42,7 +42,8 @@ sub _columns_info_for { $info->{default_value} = $1; } elsif ($def =~ /^NULL:?/i) { - $info->{default_value} = \'null'; + my $null = 'null'; + $info->{default_value} = \$null; } else { $info->{default_value} = \$def; diff --git a/t/10_03pg_common.t b/t/10_03pg_common.t index b93c092..eb845a7 100644 --- a/t/10_03pg_common.t +++ b/t/10_03pg_common.t @@ -100,14 +100,17 @@ my $tester = dbixcsl_common_tests->new( 'varchar(2)' => { data_type => 'varchar', size => 2 }, 'character(2)' => { data_type => 'char', size => 2 }, 'char(2)' => { data_type => 'char', size => 2 }, + # check that default null is correctly rewritten + 'char(3) default null' => { data_type => 'char', size => 3, + default_value => \'null' }, 'character' => { data_type => 'char', size => 1 }, 'char' => { data_type => 'char', size => 1 }, text => { data_type => 'text' }, # varchar with no size has unlimited size, we rewrite to 'text' varchar => { data_type => 'text', original => { data_type => 'varchar' } }, - # check that default NULL is correctly rewritten - 'varchar(3) default NULL' => { data_type => 'varchar', size => 3, + # check default null again (to make sure ref is safe) + 'varchar(3) default null' => { data_type => 'varchar', size => 3, default_value => \'null' }, # Datetime Types