add missing newline for no-linenumber-change dzil
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / Monotonic.pm
CommitLineData
dab1797d 1package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
97aa9a74 2
dab1797d 3use Moose;
9deabd1f 4
5# ABSTRACT: Obvious version progressions
6
dab1797d 7use Carp 'croak';
8
9with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
10
11has schema_version => (
12 isa => 'Int',
13 is => 'ro',
14 required => 1,
15);
16
17has database_version => (
18 isa => 'Int',
19 is => 'ro',
20 required => 1,
21);
22
23has to_version => (
24 isa => 'Int',
25 is => 'ro',
26 lazy_build => 1,
27);
28
29sub _build_to_version { $_[0]->schema_version }
30
31has _version => (
32 is => 'rw',
33 isa => 'Int',
34 lazy_build => 1,
35);
36
dab1797d 37sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
38sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) }
39
40sub _build__version { $_[0]->database_version }
41
42sub 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
56sub 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
721;
73
e52174e3 74# vim: ts=2 sw=2 expandtab
75
dab1797d 76__END__
77
ec167a97 78=head1 SEE ALSO
79
80This class is an implementation of
81L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
82documentation is there.