From: Arthur Axel 'fREW' Schmidt Date: Wed, 17 Mar 2010 05:49:54 +0000 (-0500) Subject: use VersionStorage in the rest of our stuff X-Git-Tag: v0.001000_01~96 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb105cfaa0a76db35042a0c862f8fd56fa8c0d2c;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git use VersionStorage in the rest of our stuff --- diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm b/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm index b1ebb78..f203066 100644 --- a/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm +++ b/lib/DBIx/Class/DeploymentHandler/HandlesVersioning.pm @@ -10,18 +10,13 @@ has schema => ( handles => [qw( schema_version )], ); -has version_rs => ( - isa => 'DBIx::Class::ResultSet', +has version_storage => ( + does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', is => 'ro', - lazy_build => 1, - handles => [qw( is_installed db_version )], + required => 1, + handles => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', ); -sub _build_version_rs { - $_[0]->schema->set_us_up_the_bomb; - $_[0]->schema->resultset('__VERSION') -} - has to_version => ( is => 'ro', lazy_build => 1, diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm index 4adc416..c02d52f 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm @@ -17,8 +17,8 @@ sub next_version_set { $self->once(!$self->once); return undef - if $self->db_version eq $self->to_version; - return [$self->db_version, $self->to_version]; + if $self->database_version eq $self->to_version; + return [$self->database_version, $self->to_version]; } diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm index 6566de7..191ac1a 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm @@ -11,7 +11,7 @@ has ordered_versions => ( required => 1, trigger => sub { my $to_version = $_[0]->to_version; - my $db_version = $_[0]->db_version; + my $db_version = $_[0]->database_version; croak 'to_version not in ordered_versions' unless grep { $to_version eq $_ } @{ $_[1] }; @@ -33,11 +33,11 @@ has _version_idx => ( method _inc_version_idx { $self->_version_idx($self->_version_idx + 1 ) } method _build__version_idx { - my $start = $self->version_rs->db_version; + my $start = $self->database_version; my $idx = 0; for (@{$self->ordered_versions}) { return $idx - if $_ eq $self->db_version; + if $_ eq $self->database_version; $idx++; } croak 'database version not found in ordered_versions!'; diff --git a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm index e72c133..9d307bc 100644 --- a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm @@ -16,7 +16,8 @@ sub _build_version_handler { my $self = shift; my $args = { - schema => $self->schema, + schema => $self->schema, + version_storage => $self->version_storage, }; $args->{to_version} = $self->to_version if $self->has_to_version; diff --git a/t/03_explict_versions.t b/t/03_explict_versions.t index d6232f9..c341d12 100644 --- a/t/03_explict_versions.t +++ b/t/03_explict_versions.t @@ -25,9 +25,11 @@ my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, databases => 'SQLite', - sqltargs => { add_drop_table => 0 }, + sqltargs => { add_drop_table => 0 }, }); +my $v_storage = $handler->version_storage; + my $version = $s->schema_version(); $handler->prepare_install(); @@ -40,6 +42,7 @@ my $versions = [map "$_.0", 0..100]; schema => $s, ordered_versions => $versions, to_version => '1.0', + version_storage => $v_storage, }); ok $vh, 'VersionHandler gets instantiated'; @@ -52,6 +55,7 @@ my $versions = [map "$_.0", 0..100]; schema => $s, ordered_versions => $versions, to_version => '5.0', + version_storage => $v_storage, }); ok $vh, 'VersionHandler gets instantiated'; @@ -68,6 +72,7 @@ dies_ok { schema => $s, ordered_versions => $versions, to_version => '0.0', + version_storage => $v_storage, }); } 'cannot request a version before the current version'; diff --git a/t/04_db_schema_versions.t b/t/04_db_schema_versions.t index 2510ed6..2dedd1a 100644 --- a/t/04_db_schema_versions.t +++ b/t/04_db_schema_versions.t @@ -27,7 +27,7 @@ my $handler = DBIx::Class::DeploymentHandler->new({ databases => 'SQLite', sqltargs => { add_drop_table => 0 }, }); - +my $v_storage = $handler->version_storage; my $version = $s->schema_version(); $handler->prepare_install(); @@ -37,6 +37,7 @@ $handler->install; schema => $s, ordered_versions => $versions, to_version => '5.0', + version_storage => $v_storage, }); ok( $vh, 'VersionHandler gets instantiated' ); @@ -49,6 +50,7 @@ $handler->install; my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ schema => $s, ordered_versions => $versions, + version_storage => $v_storage, }); ok( $vh, 'VersionHandler gets instantiated' ); @@ -59,6 +61,7 @@ $handler->install; my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ schema => $s, ordered_versions => $versions, + version_storage => $v_storage, }); ok( $vh, 'VersionHandler gets instantiated' ); @@ -71,6 +74,7 @@ $handler->install; my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({ schema => $s, ordered_versions => $versions, + version_storage => $v_storage, }); ok( $vh, 'VersionHandler gets instantiated' );