From: Arthur Axel 'fREW' Schmidt Date: Sat, 8 May 2010 15:30:40 +0000 (-0500) Subject: I have no idea why this stupid thing is not working X-Git-Tag: v0.001000_07~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=bf7a4e56e325cfed43caf682e29bd3fac1355c90;hp=961d42b1b180a6fa3abf7d751ef56e184e8b6d96 I have no idea why this stupid thing is not working --- diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index cf36dfa..996a58b 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -104,6 +104,10 @@ method __ddl_consume_with_prefix($type, $versions, $prefix) { return [@files{sort keys %files}] } +method _ddl_preinstall_consume_filenames($type, $version) { + $self->__ddl_consume_with_prefix($type, [ $version ], 'preinstall') +} + method _ddl_schema_consume_filenames($type, $version) { $self->__ddl_consume_with_prefix($type, [ $version ], 'schema') } @@ -181,7 +185,7 @@ method _run_sql_and_perl($filenames) { carp "$filename should define a run method that takes a schema but it didn't!"; } } else { - croak "A file got to deploy that wasn't sql or perl!"; + croak "A file ($filename) got to deploy that wasn't sql or perl!"; } } @@ -200,6 +204,37 @@ sub deploy { )); } +sub preinstall_scripts { + my $self = shift; + my $version = shift || $self->schema_version; + + my @files = @{$self->_ddl_preinstall_consume_filenames( + $self->storage->sqlt_type, + $version, + )}; + + for my $filename (@files) { + # We ignore sql for now (till I figure out what to do with it) + if ( $filename =~ /^(.+)\.pl$/ ) { + my $package = $1; + my $filedata = do { local( @ARGV, $/ ) = $filename; <> }; + # make the package name more palateable to perl + $package =~ s/\W/_/g; + + no warnings 'redefine'; + eval "package $package;\n\n$filedata"; + use warnings; + if (my $fn = $package->can('run')) { + $fn->() + } else { + carp "$filename should define a run sub but it didn't!"; + } + } else { + croak "A file ($filename) got to preinstall_scripts that wasn't sql or perl!"; + } + } +} + sub _prepare_install { my $self = shift; my $sqltargs = { %{$self->sql_translator_args}, %{shift @_} }; diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm index 4d4d818..adc2693 100644 --- a/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm +++ b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm @@ -3,6 +3,8 @@ use Moose::Role; # ABSTRACT: Interface for deploy methods +requires 'preinstall_scripts'; + requires 'prepare_deploy'; requires 'deploy'; diff --git a/t/deploy_methods/sql_translator.t b/t/deploy_methods/sql_translator.t index 21a0197..2d5607d 100644 --- a/t/deploy_methods/sql_translator.t +++ b/t/deploy_methods/sql_translator.t @@ -28,6 +28,16 @@ VERSION1: { ok( $dm, 'DBIC::DH::DM::SQL::Translator gets instantiated correctly' ); $dm->prepare_deploy; + + mkpath(catfile(qw( t sql SQLite preinstall 1.0 ))); + open my $prerun, '>', + catfile(qw( t sql SQLite preinstall 1.0 003-semiautomatic.pl )); + print {$prerun} "sub run {use File::Touch; touch(q(foobar));}"; + close $prerun; + $dm->preinstall_scripts('1.0'); + + ok -e 'foobar'; + { my $warned = 0; local $SIG{__WARN__} = sub{$warned = 1}; @@ -161,7 +171,7 @@ VERSION2: { bar => 'frew', baz => 'frew', }) - } 'schema is downpgrayyed'; + } 'schema is downgrayyed'; $dm->upgrade_single_step([qw( 1.0 2.0 )]); }