From: Dagfinn Ilmari Mannsåker Date: Sat, 5 Apr 2014 20:56:18 +0000 (+0100) Subject: Fix dumping unique indexes with DBD::Pg < 1.50 X-Git-Tag: 0.07040~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=a01ac8ee4339fe7a212934ad51ea34cd9b4921cc Fix dumping unique indexes with DBD::Pg < 1.50 --- diff --git a/Changes b/Changes index 7b47e7f..9db5846 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Add options to omit the version and timestamp from the generated code (RT#92300) - Skip dumping unique indexes with expressions (RT#93613) + - Fix dumping unique indexes with DBD::Pg < 1.50 0.07039 2014-01-06 - Fix table listing with DBD::DB2 >= 1.85 (RT#91764) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index e673b80..178b55c 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -125,13 +125,12 @@ sub _table_uniq_info { pg_catalog.pg_index x JOIN pg_catalog.pg_class c ON c.oid = x.indrelid JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid - JOIN pg_catalog.pg_constraint con ON con.conname = i.relname - LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace + JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE x.indisunique = 't' AND + x.indpred IS NULL AND c.relkind = 'r' AND i.relkind = 'i' AND - con.contype = 'u' AND n.nspname = ? AND c.relname = ?} ); @@ -149,10 +148,8 @@ sub _table_uniq_info { push(@col_names, $self->_lc($name_aref->[0])) if $name_aref; } - if(!@col_names) { - warn "Failed to parse UNIQUE constraint $indexname on $table"; - } - else { + # skip indexes with missing column names (e.g. expression indexes) + if(@col_names == @col_nums) { push(@uniqs, [ $indexname => \@col_names ]); } } diff --git a/t/10_03pg_common.t b/t/10_03pg_common.t index 1da712b..c1b75b3 100644 --- a/t/10_03pg_common.t +++ b/t/10_03pg_common.t @@ -249,6 +249,8 @@ my $tester = dbixcsl_common_tests->new( q{ create table pg_loader_test12 ( id integer not null, + value integer, + active boolean, name text ) }, @@ -262,6 +264,16 @@ my $tester = dbixcsl_common_tests->new( upper(name), id ) }, + q{ + create unique index pg_loader_test12_value on pg_loader_test12 ( + value + ) + }, + q{ + create unique index pg_loader_test12_name_active on pg_loader_test12 ( + name + ) where active + }, ], pre_drop_ddl => [ 'DROP SCHEMA dbicsl_test CASCADE', @@ -466,8 +478,10 @@ my $tester = dbixcsl_common_tests->new( isa_ok $schema->resultset($monikers->{pg_loader_test11})->result_source, 'DBIx::Class::ResultSource::View', 'views have table_class set correctly'; - is_deeply { $schema->source($monikers->{pg_loader_test12})->unique_constraints }, - {}, 'unique indexes with expressions are not dumped'; + is_deeply + { $schema->source($monikers->{pg_loader_test12})->unique_constraints }, + { pg_loader_test12_value => ['value'] }, + 'unique indexes are dumped correctly'; }, }, );