X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDeploymentHandler%2FDeployMethod%2FSQL%2FTranslator.pm;fp=lib%2FDBIx%2FClass%2FDeploymentHandler%2FDeployMethod%2FSQL%2FTranslator.pm;h=a706b62a22b4ccf2b8c69b7bf9dfb43ac2ef452f;hp=c602bf916608aee4e3a9538b4c9645e24073056d;hb=f36afe83b92e3948ebcdf68c1f3e03fd46000e70;hpb=5d7b27cf7721455fb35119ea3a5995d9d7715031 diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index c602bf9..a706b62 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -97,7 +97,7 @@ method __ddl_consume_with_prefix($type, $versions, $prefix) { } opendir my($dh), $dir; - my %files = map { $_ => "$dir/$_" } grep { /\.(?:sql|pl)$/ && -f "$dir/$_" } readdir $dh; + my %files = map { $_ => "$dir/$_" } grep { /\.(?:sql|pl|sql-\w+)$/ && -f "$dir/$_" } readdir $dh; closedir $dh; if (-d $common) { @@ -153,14 +153,12 @@ method _ddl_schema_down_produce_filename($type, $versions, $dir) { return catfile( $dirname, '001-auto.sql'); } -method _run_sql($filename) { +method _run_sql_array($sql) { my $storage = $self->storage; - log_debug { "[DBICDH] Running SQL from $filename" }; - my @sql = @{$self->_read_sql_file($filename)}; - my $sql .= join "\n", @sql; - log_trace { "[DBICDH] Running SQL $sql" }; - foreach my $line (@sql) { + my $ret = join "\n", @$sql; + log_trace { "[DBICDH] Running SQL $sql" }; + foreach my $line (@{$sql}) { $storage->_query_start($line); try { # do a dbh_do cycle here, as we need some error checking in @@ -172,7 +170,12 @@ method _run_sql($filename) { } $storage->_query_end($line); } - return $sql + return $ret +} + +method _run_sql($filename) { + log_debug { "[DBICDH] Running SQL from $filename" }; + return $self->_run_sql_array($self->_read_sql_file($filename)); } method _run_perl($filename) { @@ -192,13 +195,22 @@ method _run_perl($filename) { carp "$filename should define an anonymouse sub that takes a schema but it didn't!"; } } - -method _run_serialized_sql($filename, $type) { +{ + my $json; + + method _run_serialized_sql($filename, $type) { + if ($type eq 'json') { + require JSON; + $json ||= JSON->new->pretty; + my @sql = @{$json->decode($filename)}; + } else { + croak "A file ($filename) got to deploy that wasn't sql or perl!"; + } + } } method _run_sql_and_perl($filenames) { - my $storage = $self->storage; my @files = @{$filenames}; my $guard = $self->schema->txn_scope_guard if $self->txn_wrap;