From: Arthur Axel 'fREW' Schmidt Date: Tue, 18 May 2010 00:19:49 +0000 (-0500) Subject: preinstall may no longer connect to the database X-Git-Tag: v0.001000_10~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9faec51a058ada506be90ba588617b9643c8470b;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git preinstall may no longer connect to the database --- diff --git a/Changes b/Changes index f2f7dd7..750ef42 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for {{$dist->name}} {{$NEXT}} + - preconnect should not connect to the database 0.001000_09 2010-05-15 23:19:05 CST6CDT - Schemata is no longer required to add version checking component diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index c56243b..586eee1 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -176,9 +176,9 @@ method _run_sql_and_perl($filenames) { my $fn = eval "$filedata"; use warnings; - if ($@) { + if ($@) { carp "$filename failed to compile: $@"; - } elsif (ref $fn eq 'CODE') { + } elsif (ref $fn eq 'CODE') { $fn->($self->schema) } else { carp "$filename should define an anonymouse sub that takes a schema but it didn't!"; @@ -204,11 +204,13 @@ sub deploy { } sub preinstall { - my $self = shift; - my $version = shift || $self->schema_version; + my $self = shift; + my $args = shift; + my $version = $args->{version} || $self->schema_version; + my $storage_type = $args->{storage_type} || $self->storage->sqlt_type; my @files = @{$self->_ddl_preinstall_consume_filenames( - $self->storage->sqlt_type, + $storage_type, $version, )}; @@ -217,13 +219,13 @@ sub preinstall { if ( $filename =~ /^(.+)\.pl$/ ) { my $filedata = do { local( @ARGV, $/ ) = $filename; <> }; - no warnings 'redefine'; + no warnings 'redefine'; my $fn = eval "$filedata"; use warnings; - if ($@) { + if ($@) { carp "$filename failed to compile: $@"; - } elsif (ref $fn eq 'CODE') { + } elsif (ref $fn eq 'CODE') { $fn->() } else { carp "$filename should define an anonymous sub but it didn't!"; diff --git a/t/04-preconnect.t b/t/04-preconnect.t new file mode 100644 index 0000000..6260194 --- /dev/null +++ b/t/04-preconnect.t @@ -0,0 +1,40 @@ +#!perl + +use strict; +use warnings; + +use lib 't/lib'; +use DBICDHTest; +use DBIx::Class::DeploymentHandler; +use aliased 'DBIx::Class::DeploymentHandler', 'DH'; + +use File::Path qw(remove_tree mkpath); +use Test::More; +use Test::Exception; + +DBICDHTest::ready; + +my $db = 'dbi:SQLite:db.db'; +my @connection = ($db, '', '', { ignore_version => 1, }, { on_connect_do => sub { die }}); +my $sql_dir = 't/sql'; + +VERSION1: { + use_ok 'DBICVersion_v1'; + my $s = DBICVersion::Schema->connect(@connection); + $DBICVersion::Schema::VERSION = 1; + ok($s, 'DBICVersion::Schema 1 instantiates correctly'); + ok !$s->storage->connected, 'creating schema did not connect'; + my $handler = DH->new({ + upgrade_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + sql_translator_args => { add_drop_table => 0 }, + }); + ok !$s->storage->connected, 'creating handler did not connect'; + ok($handler, 'DBIx::Class::DeploymentHandler w/1 instantiates correctly'); + + mkpath('t/sql/SQLite/preinstall/1'); + $handler->preinstall({ version => 1, storage_type => 'SQLite' }); + ok !$s->storage->connected, 'creating schema did not connect'; +} +done_testing;