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