From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Mar 2010 19:06:18 +0000 (-0500) Subject: add monotonic X-Git-Tag: v0.001000_01~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=1bf789ff40fc19c3817854b8a1b544a3742a12be;hp=41219a5d4f081af0ad0507a465101a21546c1a4b add monotonic --- diff --git a/TODO b/TODO index bdf791c..18b211c 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ make recommended bundle (monotonic) -run arbitrary perl from migration scripts +run arbitrary perl from migration scripts (tests) make deploy_version_storage pod consider renaming to_version so that upgrades are less confusing to talk about diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/Monotonic.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/Monotonic.pm index 6e7c7c1..b3dcfac 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/Monotonic.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/Monotonic.pm @@ -30,12 +30,6 @@ has _version => ( lazy_build => 1, ); -sub BUILD { - croak "you are trying to upgrade and your current version is greater\n". - "than the version you are trying to upgrade to. Either downgrade\n". - "or update your schema" if $_[0]->to_version < $_[0]->_version; -} - sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) } sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) } @@ -43,20 +37,30 @@ sub _build__version { $_[0]->database_version } sub previous_version_set { my $self = shift; - return undef - if $self->to_version == $self->_version; - - $self->_dec_version; - return [$self->_version, $self->_version + 1]; + if ($self->to_vesion > $self->_version) { + croak "you are trying to downgrade and your current version is less\n". + "than the version you are trying to downgrade to. Either upgrade\n". + "or update your schema" + } elsif ( $self->to_version == $self->_version) { + return undef + } else { + $self->_dec_version; + return [$self->_version, $self->_version + 1]; + } } sub next_version_set { my $self = shift; - return undef - if $self->to_version == $self->_version; - - $self->_inc_version; - return [$self->_version - 1, $self->_version]; + if ($self->to_vesion < $self->_version) { + croak "you are trying to upgrade and your current version is greater\n". + "than the version you are trying to upgrade to. Either downgrade\n". + "or update your schema" + } elsif ( $self->to_version == $self->_version) { + return undef + } else { + $self->_inc_version; + return [$self->_version - 1, $self->_version]; + } } __PACKAGE__->meta->make_immutable;