[Bast-commits] r4484 - in DBIx-Class/0.08/branches/parser_fk_index:
lib/DBIx/Class/Relationship lib/SQL/Translator/Parser/DBIx t
t/lib/DBICTest/Schema
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Tue Jun 10 20:40:42 BST 2008
Author: lukes
Date: 2008-06-10 20:40:42 +0100 (Tue, 10 Jun 2008)
New Revision: 4484
Modified:
DBIx-Class/0.08/branches/parser_fk_index/lib/DBIx/Class/Relationship/Base.pm
DBIx-Class/0.08/branches/parser_fk_index/lib/SQL/Translator/Parser/DBIx/Class.pm
DBIx-Class/0.08/branches/parser_fk_index/t/99dbic_sqlt_parser.t
DBIx-Class/0.08/branches/parser_fk_index/t/lib/DBICTest/Schema/TwoKeys.pm
Log:
allow add_fk_index param to be specified in rel def
Modified: DBIx-Class/0.08/branches/parser_fk_index/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/branches/parser_fk_index/lib/DBIx/Class/Relationship/Base.pm 2008-06-10 19:09:24 UTC (rev 4483)
+++ DBIx-Class/0.08/branches/parser_fk_index/lib/DBIx/Class/Relationship/Base.pm 2008-06-10 19:40:42 UTC (rev 4484)
@@ -116,6 +116,12 @@
until the end of the transaction. Currently, only the PostgreSQL producer
actually supports this.
+=item add_fk_index
+
+Tells L<SQL::Translator> to add an index for this constraint. Can also be
+specified globally in the args to L<DBIx::Class::Schema/deploy> or
+L<DBIx::Class::Schema/create_ddl_dir>. Default is on, set to 0 to disable.
+
=back
=head2 register_relationship
Modified: DBIx-Class/0.08/branches/parser_fk_index/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/parser_fk_index/lib/SQL/Translator/Parser/DBIx/Class.pm 2008-06-10 19:09:24 UTC (rev 4483)
+++ DBIx-Class/0.08/branches/parser_fk_index/lib/SQL/Translator/Parser/DBIx/Class.pm 2008-06-10 19:40:42 UTC (rev 4484)
@@ -112,6 +112,9 @@
my @rels = $source->relationships();
my %created_FK_rels;
+
+ # global add_fk_index set in parser_args
+ my $add_fk_index = (exists $args->{add_fk_index} && ($args->{add_fk_index} == 0)) ? 0 : 1;
foreach my $rel (sort @rels)
{
@@ -142,6 +145,9 @@
}
my $is_deferrable = $rel_info->{attrs}{is_deferrable};
+
+ # global parser_args add_fk_index param can be overridden on the rel def
+ my $add_fk_index_rel = (exists $rel_info->{attrs}{add_fk_index}) ? $rel_info->{attrs}{add_fk_index} : $add_fk_index;
# Make sure we dont create the same foreign key constraint twice
my $key_test = join("\x00", @keys);
@@ -176,7 +182,7 @@
(defined $is_deferrable ? ( deferrable => $is_deferrable ) : ()),
);
- unless (exists $args->{add_fk_index} && ($args->{add_fk_index} == 0)) {
+ if ($add_fk_index_rel) {
my $index = $table->add_index(
name => join('_', $table->name, 'idx', @keys),
fields => \@keys,
Modified: DBIx-Class/0.08/branches/parser_fk_index/t/99dbic_sqlt_parser.t
===================================================================
--- DBIx-Class/0.08/branches/parser_fk_index/t/99dbic_sqlt_parser.t 2008-06-10 19:09:24 UTC (rev 4483)
+++ DBIx-Class/0.08/branches/parser_fk_index/t/99dbic_sqlt_parser.t 2008-06-10 19:40:42 UTC (rev 4484)
@@ -23,6 +23,7 @@
my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
my @indices = $table->get_indices;
my $index_count = scalar(@indices);
+ $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
is($index_count, $fk_count, "correct number of indices for $source with no args");
}
}
@@ -36,6 +37,7 @@
my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
my @indices = $table->get_indices;
my $index_count = scalar(@indices);
+ $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
}
}
Modified: DBIx-Class/0.08/branches/parser_fk_index/t/lib/DBICTest/Schema/TwoKeys.pm
===================================================================
--- DBIx-Class/0.08/branches/parser_fk_index/t/lib/DBICTest/Schema/TwoKeys.pm 2008-06-10 19:09:24 UTC (rev 4483)
+++ DBIx-Class/0.08/branches/parser_fk_index/t/lib/DBICTest/Schema/TwoKeys.pm 2008-06-10 19:40:42 UTC (rev 4484)
@@ -11,7 +11,7 @@
__PACKAGE__->set_primary_key(qw/artist cd/);
__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' );
-__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0 } );
+__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0, add_fk_index => 0 } );
__PACKAGE__->has_many(
'fourkeys_to_twokeys', 'DBICTest::Schema::FourKeys_to_TwoKeys', {
More information about the Bast-commits
mailing list