File Coverage

blib/lib/DBIx/Class/DeploymentHandler/VersionHandler/Monotonic.pm
Criterion Covered Total %
statement 26 26 100.0
branch 9 10 90.0
condition n/a
subroutine 9 9 100.0
pod 0 2 0.0
total 44 47 93.6


line stmt bran cond sub pod time code
1             package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
2             $DBIx::Class::DeploymentHandler::VersionHandler::Monotonic::VERSION = '0.002233';
3 12     12   89731 use Moose;
  12         383273  
  12         90  
4 12     12   71444 use DBIx::Class::DeploymentHandler::Types;
  12         32  
  12         324  
5              
6             # ABSTRACT: Obvious version progressions
7              
8 12     12   67 use Carp 'croak';
  12         29  
  12         5707  
9              
10             with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
11              
12             has schema_version => (
13             isa => 'DBIx::Class::DeploymentHandler::VersionNonObj',
14             coerce => 1,
15             is => 'ro',
16             required => 1,
17             );
18              
19             has initial_version => (
20             isa => 'Int',
21             is => 'ro',
22             required => 1,
23             );
24              
25             has to_version => (
26             isa => 'DBIx::Class::DeploymentHandler::VersionNonObj',
27             coerce => 1,
28             is => 'ro',
29             lazy_build => 1,
30             );
31              
32             sub _build_to_version {
33 1     1   37 my $version = $_[0]->schema_version;
34 1 50       34 ref($version) ? $version->numify : $version;
35             }
36              
37             has _version => (
38             is => 'rw',
39             isa => 'Int',
40             lazy_build => 1,
41             );
42              
43 18     18   594 sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
44 11     11   361 sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) }
45              
46 25     25   843 sub _build__version { $_[0]->initial_version }
47              
48             # provide backwards compatibility for initial_version/database_version
49             around BUILDARGS => sub {
50             my $orig = shift;
51             my $class = shift;
52              
53             my $args = $class->$orig(@_);
54             $args->{initial_version} = $args->{database_version}
55             if exists $args->{database_version} && !exists $args->{initial_version};
56             return $args;
57             };
58              
59             sub previous_version_set {
60 21     21 0 2558 my $self = shift;
61 21 100       793 if ($self->to_version > $self->_version) {
    100          
62 1         116 croak "you are trying to downgrade and your current version is less\n".
63             "than the version you are trying to downgrade to. Either upgrade\n".
64             "or update your schema"
65             } elsif ( $self->to_version == $self->_version) {
66             return undef
67 9         92 } else {
68 11         43 $self->_dec_version;
69 11         357 return [$self->_version + 1, $self->_version];
70             }
71             }
72              
73             sub next_version_set {
74 36     36 0 3924 my $self = shift;
75 36 100       1342 if ($self->to_version < $self->initial_version) {
    100          
76 1         173 croak "you are trying to upgrade and your current version is greater\n".
77             "than the version you are trying to upgrade to. Either downgrade\n".
78             "or update your schema"
79             } elsif ( $self->to_version == $self->_version) {
80             return undef
81 17         416 } else {
82 18         73 $self->_inc_version;
83 18         591 return [$self->_version - 1, $self->_version];
84             }
85             }
86              
87             __PACKAGE__->meta->make_immutable;
88              
89             1;
90              
91             # vim: ts=2 sw=2 expandtab
92              
93             __END__
94              
95             =pod
96              
97             =head1 NAME
98              
99             DBIx::Class::DeploymentHandler::VersionHandler::Monotonic - Obvious version progressions
100              
101             =head1 SEE ALSO
102              
103             This class is an implementation of
104             L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
105             documentation is there.
106              
107             =head1 AUTHOR
108              
109             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
114              
115             This is free software; you can redistribute it and/or modify it under
116             the same terms as the Perl 5 programming language system itself.
117              
118             =cut