add monotonic
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / Monotonic.pm
CommitLineData
dab1797d 1package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
2use Moose;
3use Carp 'croak';
4
5with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
6
7has schema_version => (
8 isa => 'Int',
9 is => 'ro',
10 required => 1,
11);
12
13has database_version => (
14 isa => 'Int',
15 is => 'ro',
16 required => 1,
17);
18
19has to_version => (
20 isa => 'Int',
21 is => 'ro',
22 lazy_build => 1,
23);
24
25sub _build_to_version { $_[0]->schema_version }
26
27has _version => (
28 is => 'rw',
29 isa => 'Int',
30 lazy_build => 1,
31);
32
dab1797d 33sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
34sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) }
35
36sub _build__version { $_[0]->database_version }
37
38sub previous_version_set {
39 my $self = shift;
1bf789ff 40 if ($self->to_vesion > $self->_version) {
41 croak "you are trying to downgrade and your current version is less\n".
42 "than the version you are trying to downgrade to. Either upgrade\n".
43 "or update your schema"
44 } elsif ( $self->to_version == $self->_version) {
45 return undef
46 } else {
47 $self->_dec_version;
48 return [$self->_version, $self->_version + 1];
49 }
dab1797d 50}
51
52sub next_version_set {
53 my $self = shift;
1bf789ff 54 if ($self->to_vesion < $self->_version) {
55 croak "you are trying to upgrade and your current version is greater\n".
56 "than the version you are trying to upgrade to. Either downgrade\n".
57 "or update your schema"
58 } elsif ( $self->to_version == $self->_version) {
59 return undef
60 } else {
61 $self->_inc_version;
62 return [$self->_version - 1, $self->_version];
63 }
dab1797d 64}
65
66__PACKAGE__->meta->make_immutable;
67
681;
69
70__END__
71
72vim: ts=2 sw=2 expandtab