X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDeploymentHandler%2FVersionHandler%2FMonotonic.pm;fp=lib%2FDBIx%2FClass%2FDeploymentHandler%2FVersionHandler%2FMonotonic.pm;h=b3dcfacdbfb108c4e1c4ed7d9680a9f9978530d8;hb=1bf789ff40fc19c3817854b8a1b544a3742a12be;hp=6e7c7c1631eb79c0e24dc23f1bec6b7de07fb3f4;hpb=41219a5d4f081af0ad0507a465101a21546c1a4b;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git 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;