huge refactoring to clean up SQLTDM and allow running of arbitraty perl in upgrades...
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / Monotonic.pm
CommitLineData
dab1797d 1package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
2use Moose;
3use Carp 'croak';
4
5with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
6
7has schema_version => (
8 isa => 'Int',
9 is => 'ro',
10 required => 1,
11);
12
13has database_version => (
14 isa => 'Int',
15 is => 'ro',
16 required => 1,
17);
18
19has to_version => (
20 isa => 'Int',
21 is => 'ro',
22 lazy_build => 1,
23);
24
25sub _build_to_version { $_[0]->schema_version }
26
27has _version => (
28 is => 'rw',
29 isa => 'Int',
30 lazy_build => 1,
31);
32
33sub BUILD {
34 croak "you are trying to upgrade and your current version is greater\n".
35 "than the version you are trying to upgrade to. Either downgrade\n".
36 "or update your schema" if $_[0]->to_version < $_[0]->_version;
37}
38
39sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
40sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) }
41
42sub _build__version { $_[0]->database_version }
43
44sub previous_version_set {
45 my $self = shift;
46 return undef
47 if $self->to_version == $self->_version;
48
49 $self->_dec_version;
50 return [$self->_version, $self->_version + 1];
51}
52
53sub next_version_set {
54 my $self = shift;
55 return undef
56 if $self->to_version == $self->_version;
57
58 $self->_inc_version;
59 return [$self->_version - 1, $self->_version];
60}
61
62__PACKAGE__->meta->make_immutable;
63
641;
65
66__END__
67
68vim: ts=2 sw=2 expandtab