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