From: Luke Saunders Date: Wed, 15 Aug 2007 23:45:32 +0000 (+0000) Subject: moved upgrade file reading into upgrade from _on_connect X-Git-Tag: v0.08240~545^2~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=b98d9e8a270c25ca5c1ef1016ff561a5feb2112a moved upgrade file reading into upgrade from _on_connect --- diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index aa76fff..c492288 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -117,33 +117,11 @@ sub _on_connect return 1; } - $file = $self->ddl_filename( - $self->storage->sqlt_type, - $self->upgrade_directory, - $self->schema_version, - $pversion, - ); -# $file =~ s/@{[ $self->schema_version ]}/"${pversion}-" . $self->schema_version/e; - if(!-f $file) - { - warn "Upgrade not possible, no upgrade file found ($file)\n"; - return; - } - - my $fh; - open $fh, "<$file" or warn("Can't open upgrade file, $file ($!)"); - my @data = split(/[;\n]/, join('', <$fh>)); - close($fh); - @data = grep { $_ && $_ !~ /^-- / } @data; - @data = grep { $_ !~ /^(BEGIN TRANACTION|COMMIT)/m } @data; - - $self->_filedata(\@data); ## Don't do this yet, do only on command? ## If we do this later, where does the Version table get updated?? warn "Versions out of sync. This is " . $self->schema_version . ", your database contains version $pversion, please call upgrade on your Schema.\n"; -# $self->upgrade($pversion, $self->schema_version); } sub get_db_version @@ -186,6 +164,28 @@ sub upgrade { my ($self) = @_; + my $file = $self->ddl_filename( + $self->storage->sqlt_type, + $self->upgrade_directory, + $self->schema_version, + $self->get_db_version, + ); + +# $file =~ s/@{[ $self->schema_version ]}/"${pversion}-" . $self->schema_version/e; + if(!-f $file) + { + warn "Upgrade not possible, no upgrade file found ($file)\n"; + return; + } + + my $fh; + open $fh, "<$file" or warn("Can't open upgrade file, $file ($!)"); + my @data = split(/[;\n]/, join('', <$fh>)); + close($fh); + @data = grep { $_ && $_ !~ /^-- / } @data; + @data = grep { $_ !~ /^(BEGIN TRANACTION|COMMIT)/m } @data; + + $self->_filedata(\@data); $self->backup() if($self->do_backup); $self->txn_do(sub { diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 82859f2..0e814ac 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1279,23 +1279,22 @@ sub create_ddl_dir if(-e $filename) { warn("$filename already exists, skipping $db"); - next; - } - - my $output = $sqlt->translate; - if(!$output) - { - warn("Failed to translate to $db, skipping. (" . $sqlt->error . ")"); - next; - } - if(!open($file, ">$filename")) - { - $self->throw_exception("Can't open $filename for writing ($!)"); + next unless ($preversion); + } else { + my $output = $sqlt->translate; + if(!$output) + { + warn("Failed to translate to $db, skipping. (" . $sqlt->error . ")"); next; - } - print $file $output; - close($file); - + } + if(!open($file, ">$filename")) + { + $self->throw_exception("Can't open $filename for writing ($!)"); + next; + } + print $file $output; + close($file); + } if($preversion) { require SQL::Translator::Diff;