From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Mar 2010 17:30:56 +0000 (-0500) Subject: fix _read_sql_file and flatten _deploy some X-Git-Tag: v0.001000_01~80 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=0d19af1d749a0fb7605b1f3a94a2adcbef830d28 fix _read_sql_file and flatten _deploy some --- diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index 17ff95d..6c53b49 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -142,28 +142,18 @@ method _ddl_schema_down_produce_filename($type, $versions, $dir) { ); } -method _deployment_statements { - my $type = $self->storage->sqlt_type; - my $version = $self->schema_version; - - for my $filename (@{$self->_ddl_schema_consume_filenames($type, $version)}) { - open my $file, q(<), $filename - or carp "Can't open $filename ($!)"; - my @rows = <$file>; - close $file; - return join '', @rows; - } -} - sub _deploy { my $self = shift; my $storage = $self->storage; my $guard = $self->schema->txn_scope_guard if $self->txn_wrap; - foreach my $line ( split /;\n/, $self->_deployment_statements ) { - $line = join '', grep { !/^--/ } split /\n/, $line; - next if !$line || $line =~ /^BEGIN TRANSACTION|^COMMIT|^\s+$/; + foreach my $line ( + map @{$self->_read_sql_file($_)}, @{$self->_ddl_schema_consume_filenames( + $self->storage->sqlt_type, + $self->schema_version + )} + ) { $storage->_query_start($line); try { # do a dbh_do cycle here, as we need some error checking in @@ -353,16 +343,17 @@ method _prepare_changegrade($from_version, $to_version, $version_set, $direction method _read_sql_file($file) { return unless $file; - open my $fh, '<', $file or carp("Can't open upgrade file, $file ($!)"); - my @data = split /\n/, join '', <$fh>; + open my $fh, '<', $file or carp("Can't open sql file, $file ($!)"); + my @data = split /;\n/, join '', <$fh>; close $fh; @data = grep { - $_ && - !/^--/ && - !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/m - } split /;/, - join '', @data; + $_ && # 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; }