From: Ash Berlin Date: Fri, 12 Oct 2007 17:46:55 +0000 (+0000) Subject: Remove add_index and replace it with sqlt_deploy_hook X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aaf2403d17fd75fea98d22c2ef28c42d3285ef03;p=dbsrgits%2FDBIx-Class-Historic.git Remove add_index and replace it with sqlt_deploy_hook --- diff --git a/Changes b/Changes index 48f5c5a..3aa01e8 100644 --- a/Changes +++ b/Changes @@ -8,8 +8,8 @@ Revision history for DBIx::Class 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. + - Added sqlt_deploy_hook to result classes so that indexes can be + added. 0.08007 2007-09-04 19:36:00 - patch for Oracle datetime inflation (abram@arin.net) diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 3d06ba9..4efa0d7 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -13,7 +13,7 @@ use base qw/DBIx::Class/; __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 _indexes/); + source_name/); __PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class result_class/); @@ -55,7 +55,6 @@ sub new { $new->{_relationships} = { %{$new->{_relationships}||{}} }; $new->{name} ||= "!!NAME NOT SET!!"; $new->{_columns_info_loaded} ||= 0; - $new->_indexes([]) unless $new->_indexes; return $new; } @@ -450,30 +449,6 @@ See also: L 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. Takes the same arguments -as L. - -=cut - -sub add_index { - my ($self, $idx) = @_; - - push @{ $self->_indexes }, $idx; -} - -=head2 indexes - -Returns list of secondary (i.e. non unique) indexes created on this table. - -=cut - -sub indexes { - return @{ shift->_indexes }; -} - =head2 add_relationship $source->add_relationship('relname', 'related_source', $cond, $attrs); diff --git a/lib/DBIx/Class/ResultSourceProxy.pm b/lib/DBIx/Class/ResultSourceProxy.pm index 65ea6d2..696c9a5 100644 --- a/lib/DBIx/Class/ResultSourceProxy.pm +++ b/lib/DBIx/Class/ResultSourceProxy.pm @@ -104,12 +104,4 @@ sub relationship_info { shift->result_source_instance->relationship_info(@_); } -sub add_index { - shift->result_source_instance->add_index(@_); -} - -sub indexes { - shift->result_source_instance->indexes(@_); -} - 1; diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 546f773..a53a7a5 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -109,11 +109,6 @@ sub parse { } } - foreach my $idx ( $source->indexes ) { - my $ret = $table->add_index(%$idx) - or die $table->error; - } - my @rels = $source->relationships(); my %created_FK_rels; @@ -175,6 +170,10 @@ sub parse { } } } + + if ($source->result_class->can('sqlt_deploy_hook')) { + $source->result_class->sqlt_deploy_hook($table); + } } return 1; } diff --git a/t/lib/DBICTest/Schema/Artist.pm b/t/lib/DBICTest/Schema/Artist.pm index a412bf0..424fbe9 100644 --- a/t/lib/DBICTest/Schema/Artist.pm +++ b/t/lib/DBICTest/Schema/Artist.pm @@ -41,6 +41,11 @@ __PACKAGE__->has_many( { cascade_copy => 0 } # this would *so* not make sense ); -__PACKAGE__->add_index({ name => 'artist_name', fields => ['name'],}); +sub sqlt_deploy_hook { + my ($self, $sqlt_table) = @_; + + $sqlt_table->add_index( name => 'artist_name', fields => ['name'] ) + or die $sqlt_table->error; +} 1;