foreach my $moniker (@monikers)
{
- #eval "use $tableclass";
- #print("Can't load $tableclass"), next if($@);
my $source = $dbixschema->source($moniker);
next if $seen_tables{$source->name}++;
my $colcount = 0;
foreach my $col ($source->columns)
{
- # assuming column_info in dbix is the same as DBI (?)
+ # assuming column_info in dbic is the same as DBI (?)
# data_type is a number, column_type is text?
my %colinfo = (
name => $col,
$source->result_class->sqlt_deploy_hook($table);
}
}
+
+ if ($dbixschema->can('sqlt_deploy_hook')) {
+ $dbixschema->sqlt_deploy_hook($schema);
+ }
+
return 1;
}
my $schema = DBICTest->init_schema;
-plan tests => 55;
+plan tests => 56;
my $translator = SQL::Translator->new(
parser_args => {
ok($output, "SQLT produced someoutput")
or diag($translator->error);
-
# Note that the constraints listed here are the only ones that are tested -- if
# more exist in the Schema than are listed here and all listed constraints are
# correct, the test will still pass. If you add a class with UNIQUE or FOREIGN
my $tschema = $translator->schema();
+# Test that the $schema->sqlt_deploy_hook was called okay and that it removed
+# the 'link' table
+ok( !defined($tschema->get_table('link')), "Link table was removed by hook");
+
# Test that nonexistent constraints are not found
my $constraint = get_constraint('FOREIGN KEY', 'cd', ['title'], 'cd', ['year']);
ok( !defined($constraint), 'nonexistent FOREIGN KEY constraint not found' );
qw/Owners BooksInLibrary/
);
+sub sqlt_deploy_hook {
+ my ($self, $sqlt_schema) = @_;
+
+ $sqlt_schema->drop_table('link');
+}
+
1;
sub sqlt_deploy_hook {
my ($self, $sqlt_table) = @_;
- $sqlt_table->add_index( name => 'artist_name', fields => ['name'] )
- or die $sqlt_table->error;
+
+ if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
+ $sqlt_table->add_index( name => 'artist_name', fields => ['name'] )
+ or die $sqlt_table->error;
+ }
}
1;