From: Dagfinn Ilmari Mannsåker Date: Tue, 29 Jan 2008 15:12:17 +0000 (+0000) Subject: Add support for ENUM value lists for MySQL X-Git-Tag: 0.04999_01~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=46bef65f454d51463a897af006afc6a253b861e9;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Add support for ENUM value lists for MySQL --- diff --git a/Changes b/Changes index 93c3288..d1063b1 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Mark foreign key columns with is_foreign_key => 1 - Add support for vendor-specific extra column attributes. - Add support for extra => { unsigned => 1 } for MySQL. + - Add support for enum value lists for MySQL - Set join_type => 'LEFT OUTER' for nullable foreign keys (patch from Bernhard Weißhuhn) - Set is_auto_increment for auto-increment columns (RT #31473) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 23b5deb..f488ba2 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -129,7 +129,10 @@ sub _extra_column_info { $extra_info{is_auto_increment} = 1 } if ($info->{mysql_type_name} =~ /\bunsigned\b/i) { - $extra_info{extra} = { unsigned => 1 }; + $extra_info{extra}{unsigned} = 1; + } + if ($info->{mysql_values}) { + $extra_info{extra}{list} = $info->{mysql_values}; } return \%extra_info; diff --git a/t/11mysql_common.t b/t/11mysql_common.t index 26575b8..bd86d93 100644 --- a/t/11mysql_common.t +++ b/t/11mysql_common.t @@ -24,19 +24,26 @@ my $tester = dbixcsl_common_tests->new( create => [ qq{ CREATE TABLE mysql_loader_test1 ( - id INTEGER UNSIGNED NOT NULL PRIMARY KEY + id INTEGER UNSIGNED NOT NULL PRIMARY KEY, + value ENUM('foo', 'bar', 'baz') ) }, ], drop => [ qw/ mysql_loader_test1 / ], - count => 1, + count => 3, run => sub { my ($schema, $monikers, $classes) = @_; my $rs = $schema->resultset($monikers->{mysql_loader_test1}); my $column_info = $rs->result_source->column_info('id'); - + is($column_info->{extra}->{unsigned}, 1, 'Unsigned MySQL columns'); + + $column_info = $rs->result_source->column_info('value'); + + like($column_info->{data_type}, qr/^enum$/i, 'MySQL ENUM type'); + is_deeply($column_info->{extra}->{list}, [qw/foo bar baz/], + 'MySQL ENUM values'); }, } );