From: Dagfinn Ilmari Mannsåker Date: Wed, 21 May 2014 16:50:59 +0000 (+0100) Subject: Fix inconsistent naming of duplicate unique constraints X-Git-Tag: 0.07040~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c4f5a4a8a6962789ae901125558f4288cb708ae;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Fix inconsistent naming of duplicate unique constraints Sort the constraints by name in _table_uniq_info, so we consistently pick the same constraint if there are several on the same set of columns. --- diff --git a/Changes b/Changes index 9db5846..53ce400 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader generated code (RT#92300) - Skip dumping unique indexes with expressions (RT#93613) - Fix dumping unique indexes with DBD::Pg < 1.50 + - Fix inconsistent naming of duplicate unique constraints 0.07039 2014-01-06 - Fix table listing with DBD::DB2 >= 1.85 (RT#91764) diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 2c23e4c..5ea00ab 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -347,7 +347,7 @@ sub _table_uniq_info { $sth->finish; my @retval; - foreach my $index_name (keys %indices) { + foreach my $index_name (sort keys %indices) { my (undef, @cols) = @{$indices{$index_name}}; # skip indexes with missing column names (e.g. expression indexes) next unless @cols == grep $_, @cols; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index ba9ddaf..3b64ede 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -75,7 +75,7 @@ EOF my ($col, $constname, $seq) = @$row; push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]); } - foreach my $keyname (keys %keydata) { + foreach my $keyname (sort keys %keydata) { my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @{$keydata{$keyname}}; push(@uniqs, [ $keyname => \@ordered_cols ]); diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm index 01be8d8..7cf69c9 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm @@ -277,8 +277,7 @@ sub _table_uniq_info { my $constraints = $self->_constraints_for($table, 'U'); - my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints; - return \@uniqs; + return [ map { [ $_ => $constraints->{$_} ] } sort keys %$constraints ]; } sub _table_fk_info { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm index 9f92fc4..d07c86b 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm @@ -150,8 +150,7 @@ EOF push @{$constraints->{$constraint_name}}, $self->_lc($column); } - my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints; - return \@uniqs; + return [ map { [ $_ => $constraints->{$_} ] } sort keys %$constraints ]; } sub _columns_info_for { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm index 8f1ec6b..38a87e5 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm @@ -366,7 +366,7 @@ EOF push @{ $uniq{$constr} }, $self->_lc($col); } - return [ map [ $_ => $uniq{$_} ], keys %uniq ]; + return [ map [ $_ => $uniq{$_} ], sort keys %uniq ]; } sub _columns_info_for { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index efd0946..02bc5ab 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -126,8 +126,7 @@ EOF push @{$constr_names{$constr_name}}, $constr_col; } - my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names; - return \@uniqs; + return [ map { [ $_ => $constr_names{$_} ] } sort keys %constr_names ]; } sub _table_comment { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index 178b55c..92ff654 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -132,7 +132,8 @@ sub _table_uniq_info { c.relkind = 'r' AND i.relkind = 'i' AND n.nspname = ? AND - c.relname = ?} + c.relname = ? + ORDER BY i.relname} ); $uniq_sth->execute($table->schema, $table->name); diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm index 7a2d8f7..989fa90 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm @@ -274,8 +274,7 @@ EOF push @{$constraints->{$constraint_name}}, $self->_lc($column); } - my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints; - return \@uniqs; + return [ map { [ $_ => $constraints->{$_} ] } sort keys %$constraints ]; } =head1 SEE ALSO diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 8a7a652..f6c856e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -226,7 +226,7 @@ sub _table_uniq_info { push @uniqs, [ $name => \@cols ]; } $sth->finish; - return \@uniqs; + return [ sort { $a->[0] cmp $b->[0] } @uniqs ]; } sub _tables_list { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm index e29abad..63a35a5 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm @@ -346,11 +346,9 @@ EOF } } - my @uniqs = map { [ $_ => $uniqs{$_} ] } keys %uniqs; - $self->dbh->do("USE [$current_db]"); - return \@uniqs; + return [ map { [ $_ => $uniqs{$_} ] } sort keys %uniqs ]; } sub _columns_info_for { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 1a3d7a8..24f101f 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -204,7 +204,7 @@ sub _table_uniq_info { my @uniqs; my $keydata = $self->_mysql_table_get_keys($table); - foreach my $keyname (keys %$keydata) { + foreach my $keyname (sort keys %$keydata) { next if $keyname eq 'PRIMARY'; push(@uniqs, [ $keyname => $keydata->{$keyname} ]); }