[Bast-commits] r5327 - in DBIx-Class/0.08/trunk: lib/DBIx/Class
lib/SQL/Translator/Parser/DBIx t
nothingmuch at dev.catalyst.perl.org
nothingmuch at dev.catalyst.perl.org
Tue Jan 20 23:10:22 GMT 2009
Author: nothingmuch
Date: 2009-01-20 23:10:22 +0000 (Tue, 20 Jan 2009)
New Revision: 5327
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm
DBIx-Class/0.08/trunk/t/86sqlt.t
Log:
Add sqlt_deploy_hook to Result Source
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-01-20 18:06:01 UTC (rev 5326)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-01-20 23:10:22 UTC (rev 5327)
@@ -13,7 +13,7 @@
__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 sqlt_deploy_callback/);
__PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
result_class/);
@@ -47,6 +47,7 @@
$new->{_relationships} = { %{$new->{_relationships}||{}} };
$new->{name} ||= "!!NAME NOT SET!!";
$new->{_columns_info_loaded} ||= 0;
+ $new->{sqlt_deploy_callback} ||= "default_sqlt_deploy_hook";
return $new;
}
@@ -1410,6 +1411,49 @@
__PACKAGE__->column_info_from_storage(1);
+=cut
+
+=head2 sqlt_deploy_hook($sqlt_table)
+
+Triggers C<sqlt_deploy_callback>.
+
+=cut
+
+sub sqlt_deploy_hook {
+ my $self = shift;
+ if ( my $hook = $self->sqlt_deploy_callback) {
+ $self->$hook(@_);
+ }
+}
+
+=head2 default_sqlt_deploy_hook($table)
+
+Delegates to a an optional C<sqlt_deploy_hook> method on the C<result_class>.
+
+This will get passed the L<SQL::Translator::Schema::Table> object when you
+deploy the schema via L</create_ddl_dir> or L</deploy>.
+
+For an example of what you can do with this, see
+L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
+
+=cut
+
+sub default_sqlt_deploy_hook {
+ my $self = shift;
+
+ my $class = $self->result_class;
+
+ if ($class and $class->can('sqlt_deploy_hook')) {
+ $class->sqlt_deploy_hook(@_);
+ }
+}
+
+=head2 sqlt_deploy_callback
+
+An attribute which contains the callback to trigger on C<sqlt_deploy_hook>.
+Defaults to C<default_sqlt_deploy_hook>. Can be a code reference or a method
+name.
+
=head1 AUTHORS
Matt S. Trout <mst at shadowcatsystems.co.uk>
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 2009-01-20 18:06:01 UTC (rev 5326)
+++ DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm 2009-01-20 23:10:22 UTC (rev 5327)
@@ -214,9 +214,7 @@
}
}
- if ($source->result_class->can('sqlt_deploy_hook')) {
- $source->result_class->sqlt_deploy_hook($table);
- }
+ $source->sqlt_deploy_hook($table)
}
if ($dbicschema->can('sqlt_deploy_hook')) {
Modified: DBIx-Class/0.08/trunk/t/86sqlt.t
===================================================================
--- DBIx-Class/0.08/trunk/t/86sqlt.t 2009-01-20 18:06:01 UTC (rev 5326)
+++ DBIx-Class/0.08/trunk/t/86sqlt.t 2009-01-20 23:10:22 UTC (rev 5327)
@@ -10,7 +10,7 @@
my $schema = DBICTest->init_schema;
-plan tests => 131;
+plan tests => 132;
my $translator = SQL::Translator->new(
parser_args => {
@@ -26,6 +26,17 @@
my $relinfo = $schema->source('Artist')->relationship_info ('cds');
local $relinfo->{attrs}{on_delete} = 'restrict';
+ $schema->source('Track')->sqlt_deploy_callback(sub {
+ my ($self, $sqlt_table) = @_;
+
+ if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
+ $sqlt_table->add_index( name => 'track_title', fields => ['title'] )
+ or die $sqlt_table->error;
+ }
+
+ $self->default_sqlt_deploy_hook($sqlt_table);
+ });
+
$translator->parser('SQL::Translator::Parser::DBIx::Class');
$translator->producer('SQLite');
@@ -258,7 +269,12 @@
{
'fields' => ['name']
},
- ]
+ ],
+ track => [
+ {
+ 'fields' => ['title']
+ }
+ ],
);
my $tschema = $translator->schema();
@@ -300,7 +316,6 @@
for my $table_index (keys %indexes) {
for my $expected_index ( @{ $indexes{$table_index} } ) {
-
ok ( get_index($table_index, $expected_index), "Got a matching index on $table_index table");
}
}
More information about the Bast-commits
mailing list