From: Tim Bunce Date: Wed, 18 Mar 2009 15:54:51 +0000 (+0000) Subject: Ignore duplicate uniq indices (including duplicates of the PK) X-Git-Tag: 0.04006~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6129a3cb34d62e95cc1d31f46b03c0466d99cfa3;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Ignore duplicate uniq indices (including duplicates of the PK) --- diff --git a/Changes b/Changes index eb010bb..3b5eb4b 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader 0.04006 Not Yet Released - Fix Oracle constraint detection for non-owned schemas (RT #35732) - Add result_base_class and schema_base_class options (RT #43977) + - Ignore duplicate uniq indices (including duplicates of the PK). 0.04005 Sat Apr 05, 2008 - Fix DB2 support diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index c6b89dd..9869713 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -672,12 +672,21 @@ sub _setup_src_meta { ); } + my %uniq_tag; # used to eliminate duplicate uniqs + my $pks = $self->_table_pk_info($table) || []; @$pks ? $self->_dbic_stmt($table_class,'set_primary_key',@$pks) : carp("$table has no primary key"); + $uniq_tag{ join("\0", @$pks) }++ if @$pks; # pk is a uniq my $uniqs = $self->_table_uniq_info($table) || []; - $self->_dbic_stmt($table_class,'add_unique_constraint',@$_) for (@$uniqs); + for (@$uniqs) { + my ($name, $cols) = @$_; + + next if $uniq_tag{ join("\0", @$cols) }++; # skip duplicates + + $self->_dbic_stmt($table_class,'add_unique_constraint', $name, $cols); + } $schema_class->register_class($table_moniker, $table_class); $schema->register_class($table_moniker, $table_class) if $schema ne $schema_class; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 75d6090..9b5738f 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -43,7 +43,7 @@ sub _monikerize { sub run_tests { my $self = shift; - plan tests => 88; + plan tests => 90; $self->create(); @@ -111,10 +111,12 @@ sub run_tests { my $moniker1 = $monikers->{loader_test1}; my $class1 = $classes->{loader_test1}; my $rsobj1 = $conn->resultset($moniker1); + check_no_duplicate_unique_constraints($class1); my $moniker2 = $monikers->{loader_test2}; my $class2 = $classes->{loader_test2}; my $rsobj2 = $conn->resultset($moniker2); + check_no_duplicate_unique_constraints($class2); my $moniker23 = $monikers->{LOADER_TEST23}; my $class23 = $classes->{LOADER_TEST23}; @@ -503,6 +505,19 @@ sub run_tests { } } +sub check_no_duplicate_unique_constraints { + my ($class) = @_; + + # unique_constraints() automatically includes the PK, if any + my %uc_cols; + ++$uc_cols{ join ", ", @$_ } + for values %{ { $class->unique_constraints } }; + my $dup_uc = grep { $_ > 1 } values %uc_cols; + + is($dup_uc, 0, "duplicate unique constraints ($class)") + or diag "uc_cols: @{[ %uc_cols ]}"; +} + sub dbconnect { my ($self, $complain) = @_;