[Bast-commits] r4490 - in DBIx-Class/0.08/branches/replication_dedux: . lib/DBIx/Class lib/DBIx/Class/Relationship lib/SQL/Translator/Parser/DBIx t t/lib/DBICTest/Schema

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Wed Jun 11 15:41:08 BST 2008


Author: jnapiorkowski
Date: 2008-06-11 15:41:07 +0100 (Wed, 11 Jun 2008)
New Revision: 4490

Added:
   DBIx-Class/0.08/branches/replication_dedux/t/99dbic_sqlt_parser.t
Modified:
   DBIx-Class/0.08/branches/replication_dedux/
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Relationship/Base.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/SQL/Translator/Parser/DBIx/Class.pm
   DBIx-Class/0.08/branches/replication_dedux/t/86sqlt.t
   DBIx-Class/0.08/branches/replication_dedux/t/94versioning.t
   DBIx-Class/0.08/branches/replication_dedux/t/lib/DBICTest/Schema/TwoKeys.pm
Log:
 r13798 at dev (orig r4486):  lukes | 2008-06-10 15:08:17 -0500
  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
 
 r13800 at dev (orig r4488):  castaway | 2008-06-11 07:25:15 -0500
 Point at "prefetch" in the get/set cache docs
 
 r13801 at dev (orig r4489):  castaway | 2008-06-11 07:54:58 -0500
 Add docs to update mentioning scalar refs and discard_changes
 



Property changes on: DBIx-Class/0.08/branches/replication_dedux
___________________________________________________________________
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:/DBIx-Class/0.08/trunk:4471
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:/DBIx-Class/0.08/trunk:4489
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/branches/replication_dedux/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Relationship/Base.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Relationship/Base.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -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/replication_dedux/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/ResultSet.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/ResultSet.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -22,8 +22,8 @@
 
 =head1 SYNOPSIS
 
-  my $rs   = $schema->resultset('User')->search(registered => 1);
-  my @rows = $schema->resultset('CD')->search(year => 2005);
+  my $rs   = $schema->resultset('User')->search({ registered => 1 });
+  my @rows = $schema->resultset('CD')->search({ year => 2005 })->all();
 
 =head1 DESCRIPTION
 
@@ -53,7 +53,10 @@
 
 =head1 OVERLOADING
 
-If a resultset is used as a number it returns the C<count()>.  However, if it is used as a boolean it is always true.  So if you want to check if a result set has any results use C<if $rs != 0>.  C<if $rs> will always be true.
+If a resultset is used in a numeric context it returns the L</count>.
+However, if it is used in a booleand context it is always true.  So if
+you want to check if a resultset has any results use C<if $rs != 0>.
+C<if $rs> will always be true.
 
 =head1 METHODS
 
@@ -1802,6 +1805,9 @@
 
 Gets the contents of the cache for the resultset, if the cache is set.
 
+The cache is populated either by using the L</prefetch> attribute to
+L</search> or by calling L</set_cache>.
+
 =cut
 
 sub get_cache {
@@ -1823,6 +1829,9 @@
 if the cache is set the resultset will return the cached objects rather
 than re-querying the database even if the cache attr is not set.
 
+The contents of the cache can also be populated by using the
+L</prefetch> attribute to L</search>.
+
 =cut
 
 sub set_cache {

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -295,6 +295,21 @@
 the same after a call to C<update>.  If you need to preserve the hashref, it is
 sufficient to pass a shallow copy to C<update>, e.g. ( { %{ $href } } )
 
+If the values passed or any of the column values set on the object
+contain scalar references, eg:
+
+  $obj->last_modified(\'NOW()');
+  # OR
+  $obj->update({ last_modified => \'NOW()' });
+
+The update will pass the values verbatim into SQL. (See
+L<SQL::Abstract> docs).  The values in your Row object will NOT change
+as a result of the update call, if you want the object to be updated
+with the actual values from the database, call L</discard_changes>
+after the update.
+
+  $obj->update()->discard_changes();
+
 =cut
 
 sub update {

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -1049,7 +1049,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
 
@@ -1103,6 +1105,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/branches/replication_dedux/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/SQL/Translator/Parser/DBIx/Class.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/SQL/Translator/Parser/DBIx/Class.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -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)
         {
@@ -143,6 +149,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);
@@ -177,15 +186,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/branches/replication_dedux/t/86sqlt.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/86sqlt.t	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/t/86sqlt.t	2008-06-11 14:41:07 UTC (rev 4490)
@@ -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/branches/replication_dedux/t/94versioning.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/94versioning.t	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/t/94versioning.t	2008-06-11 14:41:07 UTC (rev 4490)
@@ -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/branches/replication_dedux/t/99dbic_sqlt_parser.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/99dbic_sqlt_parser.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/replication_dedux/t/99dbic_sqlt_parser.t	2008-06-11 14:41:07 UTC (rev 4490)
@@ -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/branches/replication_dedux/t/lib/DBICTest/Schema/TwoKeys.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/lib/DBICTest/Schema/TwoKeys.pm	2008-06-11 12:54:58 UTC (rev 4489)
+++ DBIx-Class/0.08/branches/replication_dedux/t/lib/DBICTest/Schema/TwoKeys.pm	2008-06-11 14:41:07 UTC (rev 4490)
@@ -15,7 +15,7 @@
     {'foreign.artistid'=>'self.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