my $schema = DBICTest->init_schema;
-plan tests => 54;
+plan tests => 55;
my $translator = SQL::Translator->new(
parser_args => {
ok($output, "SQLT produced someoutput")
or diag($translator->error);
+
# Note that the constraints listed here are the only ones that are tested -- if
# more exist in the Schema than are listed here and all listed constraints are
# correct, the test will still pass. If you add a class with UNIQUE or FOREIGN
# ],
);
+my %indices = (
+ artist => [
+ {
+ 'fields' => ['name']
+ },
+ ]
+);
+
my $tschema = $translator->schema();
# Test that nonexistent constraints are not found
}
}
+for my $table_index (keys %indices) {
+ for my $expected_index ( @{ $indices{$table_index} } ) {
+
+ ok ( get_index($table_index, $expected_index), "Got a matching index on $table_index table");
+ }
+}
+
# Returns the Constraint object for the specified constraint type, table and
# columns from the SQL::Translator schema, or undef if no matching constraint
# is found.
return undef; # didn't find a matching constraint
}
+sub get_index {
+ my ($table_name, $index) = @_;
+
+ my $table = $tschema->get_table($table_name);
+
+ CAND_INDEX:
+ for my $cand_index ( $table->get_indices ) {
+
+ next CAND_INDEX if $index->{name} && $cand_index->name ne $index->{name}
+ || $index->{type} && $cand_index->type ne $index->{type};
+
+ my %idx_fields = map { $_ => 1 } $cand_index->fields;
+
+ for my $field ( @{ $index->{fields} } ) {
+ next CAND_INDEX unless $idx_fields{$field};
+ }
+
+ %idx_fields = map { $_ => 1 } @{$index->{fields}};
+ for my $field ( $cand_index->fields) {
+ next CAND_INDEX unless $idx_fields{$field};
+ }
+
+ return $cand_index;
+ }
+
+ return undef; # No matching idx
+}
+
# Test parameters in a FOREIGN KEY constraint other than columns
sub test_fk {
my ($expected, $got) = @_;