[Bast-commits] r4486 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class
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 21:08:17 BST 2008
Author: lukes
Date: 2008-06-10 21:08:17 +0100 (Tue, 10 Jun 2008)
New Revision: 4486
Added:
DBIx-Class/0.08/trunk/t/99dbic_sqlt_parser.t
Modified:
DBIx-Class/0.08/trunk/
DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm
DBIx-Class/0.08/trunk/t/86sqlt.t
DBIx-Class/0.08/trunk/t/94versioning.t
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/TwoKeys.pm
Log:
r8139 at luke-mbp (orig r4482): lukes | 2008-06-10 17:25:34 +0100
new branch for making the FK index optional
r8140 at luke-mbp (orig r4483): lukes | 2008-06-10 20:09:24 +0100
added some perldoc
r8141 at luke-mbp (orig r4484): lukes | 2008-06-10 20:40:42 +0100
allow add_fk_index param to be specified in rel def
r8142 at luke-mbp (orig r4485): lukes | 2008-06-10 21:07:56 +0100
fixed failing test
Property changes on: DBIx-Class/0.08/trunk
___________________________________________________________________
Name: svk:merge
- 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
+ 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm 2008-06-10 20:08:17 UTC (rev 4486)
@@ -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/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-06-10 20:08:17 UTC (rev 4486)
@@ -1028,7 +1028,9 @@
Additionally, the DBIx::Class parser accepts a C<sources> parameter as a hash
ref or an array ref, containing a list of source to deploy. If present, then
-only the sources listed will get deployed.
+only the sources listed will get deployed. Furthermore, you can use the
+C<add_fk_index> parser parameter to prevent the parser from creating an index for each
+FK.
=cut
@@ -1082,6 +1084,8 @@
name format. For the ALTER file, the same format is used, replacing
$version in the name with "$preversion-$version".
+See L<DBIx::Class::Schema/deploy> for details of $sqlt_args.
+
If no arguments are passed, then the following default values are used:
=over 4
Modified: DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm 2008-06-10 20:08:17 UTC (rev 4486)
@@ -23,6 +23,9 @@
# -------------------------------------------------------------------
# parse($tr, $data)
#
+# setting parser_args => { add_fk_index => 0 } will prevent
+# the auto-generation of an index for each FK.
+#
# Note that $data, in the case of this parser, is not useful.
# We're working with DBIx::Class Schemas, not data streams.
# -------------------------------------------------------------------
@@ -109,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)
{
@@ -139,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);
@@ -173,15 +182,17 @@
(defined $is_deferrable ? ( deferrable => $is_deferrable ) : ()),
);
- my $index = $table->add_index(
- name => join('_', $table->name, 'idx', @keys),
- fields => \@keys,
- type => 'NORMAL',
- );
- }
+ if ($add_fk_index_rel) {
+ my $index = $table->add_index(
+ name => join('_', $table->name, 'idx', @keys),
+ fields => \@keys,
+ type => 'NORMAL',
+ );
+ }
+ }
}
}
-
+
if ($source->result_class->can('sqlt_deploy_hook')) {
$source->result_class->sqlt_deploy_hook($table);
}
Modified: DBIx-Class/0.08/trunk/t/86sqlt.t
===================================================================
--- DBIx-Class/0.08/trunk/t/86sqlt.t 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/t/86sqlt.t 2008-06-10 20:08:17 UTC (rev 4486)
@@ -10,7 +10,7 @@
my $schema = DBICTest->init_schema;
-plan tests => 131;
+plan tests => 130;
my $translator = SQL::Translator->new(
parser_args => {
@@ -43,6 +43,7 @@
'name' => 'twokeys_fk_cd', 'index_name' => 'twokeys_idx_cd',
'selftable' => 'twokeys', 'foreigntable' => 'cd',
'selfcols' => ['cd'], 'foreigncols' => ['cdid'],
+ 'noindex' => 1,
on_delete => '', on_update => '', deferrable => 0,
},
{
@@ -388,8 +389,13 @@
"is_deferrable parameter correct for `$desc'" );
my $index = get_index( $got->table, { fields => $expected->{selfcols} } );
- ok( defined $index, "index exists for `$desc'" );
- is( $index->name, $expected->{index_name}, "index has correct name for `$desc'" );
+
+ if ($expected->{noindex}) {
+ ok( !defined $index, "index doesn't for `$desc'" );
+ } else {
+ ok( defined $index, "index exists for `$desc'" );
+ is( $index->name, $expected->{index_name}, "index has correct name for `$desc'" );
+ }
}
sub test_unique {
Modified: DBIx-Class/0.08/trunk/t/94versioning.t
===================================================================
--- DBIx-Class/0.08/trunk/t/94versioning.t 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/t/94versioning.t 2008-06-10 20:08:17 UTC (rev 4486)
@@ -15,9 +15,9 @@
unless ($dsn);
- eval "use DBD::mysql; use SQL::Translator 0.08;";
+ eval "use DBD::mysql; use SQL::Translator 0.09;";
plan $@
- ? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.08 for testing' )
+ ? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.09 for testing' )
: ( tests => 13 );
}
Added: DBIx-Class/0.08/trunk/t/99dbic_sqlt_parser.t
===================================================================
--- DBIx-Class/0.08/trunk/t/99dbic_sqlt_parser.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/99dbic_sqlt_parser.t 2008-06-10 20:08:17 UTC (rev 4486)
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+BEGIN {
+ eval "use DBD::mysql; use SQL::Translator 0.09;";
+ plan $@
+ ? ( skip_all => 'needs SQL::Translator 0.09 for testing' )
+ : ( tests => 99 );
+}
+
+my $schema = DBICTest->init_schema();
+
+{
+ my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
+
+ foreach my $source ($schema->sources) {
+ my $table = $sqlt_schema->get_table($schema->source($source)->from);
+
+ 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");
+ }
+}
+
+{
+ my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
+
+ foreach my $source ($schema->sources) {
+ my $table = $sqlt_schema->get_table($schema->source($source)->from);
+
+ 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");
+ }
+}
+
+{
+ my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
+
+ foreach my $source ($schema->sources) {
+ my $table = $sqlt_schema->get_table($schema->source($source)->from);
+
+ my @indices = $table->get_indices;
+ my $index_count = scalar(@indices);
+ is($index_count, 0, "correct number of indices for $source with add_fk_index => 0");
+ }
+}
+
+sub create_schema {
+ my $args = shift;
+
+ my $schema = $args->{schema};
+ my $additional_sqltargs = $args->{args} || {};
+
+ my $sqltargs = {
+ add_drop_table => 1,
+ ignore_constraint_names => 1,
+ ignore_index_names => 1,
+ %{$additional_sqltargs}
+ };
+
+ my $sqlt = SQL::Translator->new( $sqltargs );
+
+ $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
+ return $sqlt->translate({ data => $schema }) or die $sqlt->error;
+}
Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/TwoKeys.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/TwoKeys.pm 2008-06-10 20:07:56 UTC (rev 4485)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/TwoKeys.pm 2008-06-10 20:08:17 UTC (rev 4486)
@@ -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