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