From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Feb 2010 09:30:33 +0000 (-0600) Subject: working tests with actual version handling X-Git-Tag: v0.001000_01~115 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38bd995681bf834177f11b21ff9eb031a6724a2a;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git working tests with actual version handling --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index e595e46..06d2f9e 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -53,6 +53,11 @@ has version_rs => ( handles => [qw( is_installed db_version )], ); +has to_version => ( + is => 'ro', + lazy_build => 1, +); + method _build_version_rs { $self->schema->set_us_up_the_bomb; $self->schema->resultset('__VERSION') @@ -98,31 +103,8 @@ method upgrade { return; } - if ( $db_version eq $schema_version ) { - # croak? - carp "Upgrade not necessary\n"; - return; - } - - my @version_list = $self->ordered_schema_versions; - - # remove all versions in list above the required version - while ( @version_list && ( $version_list[-1] ne $schema_version ) ) { - pop @version_list; - } - - # remove all versions in list below the current version - while ( @version_list && ( $version_list[0] ne $db_version ) ) { - shift @version_list; - } - - # check we have an appropriate list of versions - die if @version_list < 2; - - # do sets of upgrade - while ( @version_list >= 2 ) { - $self->upgrade_single_step( $version_list[0], $version_list[1] ); - shift @version_list; + while ( my $version_list = $self->next_version_set ) { + $self->upgrade_single_step( $version_list->[0], $version_list->[1] ); } } diff --git a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm index 9cdba4c..fc80e2e 100644 --- a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm @@ -13,17 +13,21 @@ has version_handler => ( # < mst> and that role should supply those methods # < mst> then you can pass handles => as well - isa => 'DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions', + does => 'DBIx::Class::DeploymentHandler::HandlesVersioning', is => 'ro', lazy_build => 1, - handles => [qw{ ordered_schema_versions }], + handles => 'DBIx::Class::DeploymentHandler::HandlesVersioning', ); sub _build_version_handler { my $self = shift; - DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({ + + my $args = { schema => $self->schema, - }); + }; + + $args->{to_version} = $self->to_version if $self->has_to_version; + DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new($args); } 1;