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=5fb6918461f21e868ef16bf9e3d16f72b3f2ace1;hp=167e455c021c037fc7aee75b7caf7c885af8894a;hb=115c68ce0fc0e56265d201a8f7bbcf912efa86db;hpb=6e2665d32fec2eb9c168202abaf45e26fa87470e diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index 167e455..5fb6918 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -89,9 +89,9 @@ has schema_version => ( # this will probably never get called as the DBICDH # will be passing down a schema_version normally, which # is built the same way, but we leave this in place -sub _build_schema_version { +sub _build_schema_version { my $self = shift; - $self->schema->schema_version + $self->schema->schema_version } sub __ddl_consume_with_prefix { @@ -243,13 +243,7 @@ sub _run_sql_array { my ($self, $sql) = @_; my $storage = $self->storage; - $sql = [grep { - $_ && # remove blank lines - !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/ # strip txn's - } map { - s/^\s+//; s/\s+$//; # trim whitespace - join '', grep { !/^--/ } split /\n/ # remove comments - } @$sql]; + $sql = [ _split_sql_chunk( @$sql ) ]; Dlog_trace { "Running SQL $_" } $sql; foreach my $line (@{$sql}) { @@ -266,6 +260,30 @@ sub _run_sql_array { return join "\n", @$sql } +# split a chunk o' SQL into statements +sub _split_sql_chunk { + my @sql = map { split /;\n/, $_ } @_; + + for ( @sql ) { + # strip transactions + s/^(?:BEGIN|BEGIN TRANSACTION|COMMIT).*//mgi; + + # trim whitespaces + s/^\s+|\s+$//mg; + + # remove comments + s/^--.*//gm; + + # remove blank lines + s/^\n//mg; + + # put on single line + s/\n/ /g; + } + + return @sql; +} + sub _run_sql { my ($self, $filename) = @_; log_debug { "Running SQL from $filename" }; @@ -613,19 +631,10 @@ sub _read_sql_file { my ($self, $file) = @_; return unless $file; + local $/ = undef; #sluuuuuurp + open my $fh, '<', $file; - my @data = split /;\n/, join '', <$fh>; - close $fh; - - @data = grep { - $_ && # remove blank lines - !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/ # strip txn's - } map { - s/^\s+//; s/\s+$//; # trim whitespace - join '', grep { !/^--/ } split /\n/ # remove comments - } @data; - - return \@data; + return [ _split_sql_chunk( <$fh> ) ]; } sub downgrade_single_step {