clash
- InflateColumn::DateTime now accepts an extra parameter of timezone
to set timezone on the DT object (thanks Sergio Salvi)
+ - ResultSource now has an add_index method to add indices for when
+ using SQL::Translator to create tables/SQL.
0.08007 2007-09-04 19:36:00
- patch for Oracle datetime inflation (abram@arin.net)
__PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
_columns _primaries _unique_constraints name resultset_attributes
schema from _relationships column_info_from_storage source_info
- source_name/);
+ source_name _indices/);
__PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
result_class/);
$new->{_relationships} = { %{$new->{_relationships}||{}} };
$new->{name} ||= "!!NAME NOT SET!!";
$new->{_columns_info_loaded} ||= 0;
+ $new->_indices([]) unless $new->_indices;
return $new;
}
sub storage { shift->schema->storage; }
+=head2 add_index
+
+Add an index to the result source. This has no effect for DBIx::Class - it is
+just used for creating SQL with L<SQL::Translator>. Takes the same arguments
+as L<SQL::Translator::Schema::Table::add_index>.
+
+=cut
+
+sub add_index {
+ my ($self, $idx) = @_;
+
+ push @{ $self->_indices }, $idx;
+}
+
+=head2 indicies
+
+Returns list of secondary (i.e. non unique) indicies created on this table.
+
+=cut
+
+sub indices {
+ return @{ shift->_indices };
+}
+
=head2 add_relationship
$source->add_relationship('relname', 'related_source', $cond, $attrs);
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) = @_;