Commit | Line | Data |
dab1797d |
1 | package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic; |
2 | use Moose; |
3 | use Carp 'croak'; |
4 | |
5 | with 'DBIx::Class::DeploymentHandler::HandlesVersioning'; |
6 | |
7 | has schema_version => ( |
8 | isa => 'Int', |
9 | is => 'ro', |
10 | required => 1, |
11 | ); |
12 | |
13 | has database_version => ( |
14 | isa => 'Int', |
15 | is => 'ro', |
16 | required => 1, |
17 | ); |
18 | |
19 | has to_version => ( |
20 | isa => 'Int', |
21 | is => 'ro', |
22 | lazy_build => 1, |
23 | ); |
24 | |
25 | sub _build_to_version { $_[0]->schema_version } |
26 | |
27 | has _version => ( |
28 | is => 'rw', |
29 | isa => 'Int', |
30 | lazy_build => 1, |
31 | ); |
32 | |
dab1797d |
33 | sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) } |
34 | sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) } |
35 | |
36 | sub _build__version { $_[0]->database_version } |
37 | |
38 | sub 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 | |
52 | sub 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 | |
68 | 1; |
69 | |
70 | __END__ |
71 | |
72 | vim: ts=2 sw=2 expandtab |