DeploymentHandler/VersionHandler/ExplicitVersions.pm

filter: Statementstmt 100% 44 / 44 Branchbran 90.0% 9 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 90.1% 64 / 71 CC 8 SCAR 8.0
CC
8
Cov
95%
__ANON__
3.2
next_version_set
3.0
previous_version_set
3.0
CRAP 2.2
« DeploymentHandler/Deprecated.pm ↑ Summary DeploymentHandler/VersionHandler/Monotonic.pm »
1 package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
2 1 $DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions::VERSION = '0.002233';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Define your own list of versions to use for migrations
6  
7 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
10  
11 1 has schema_version => (
12 is => 'ro',
13 required => 1,
14 );
15  
16 1 has initial_version => (
17 isa => 'Str',
18 is => 'ro',
19 required => 1,
20 );
21  
22 1 has to_version => (
23 is => 'ro',
24 isa => 'Str',
25 lazy_build => 1,
26 );
27  
28 2 ▶sub _build_to_version { $_[0]->schema_version }
Subroutine _build_to_version: called CC=1 SCAR=0.0
29  
30 1 has ordered_versions => (
31 is => 'ro',
32 isa => 'ArrayRef',
33 required => 1,
34 );
35  
36 1 has _index_of_versions => (
37 is => 'ro',
38 isa => 'HashRef',
39 lazy_build => 1,
40 );
41  
42 sub _build__index_of_versions {
43 7 ▶ my %ret;
Subroutine _build__index_of_versions: called CC=2 SCAR=6.9
44 7 my $i = 0;
45 7 for (@{ $_[0]->ordered_versions }) {
46 707 $ret{$_} = $i++;
47 }
48 7 \%ret;
49 }
50  
51 1 has _version_idx => (
52 is => 'rw',
53 isa => 'Int',
54 lazy_build => 1,
55 );
56  
57 7 ▶sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->initial_version} }
Subroutine _build__version_idx: called CC=1 SCAR=0.0
58  
59 5 ▶sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
Subroutine _inc_version_idx: called CC=1 SCAR=0.0
60 4 ▶sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
Subroutine _dec_version_idx: called CC=1 SCAR=0.0
61  
62 # provide backwards compatibility for initial_version/database_version
63 around BUILDARGS => sub {
64 7 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.8
65 7 my $class = shift;
66  
67 7 my $args = $class->$orig(@_);
68 $args->{initial_version} = $args->{database_version}
69 7 ▶ if exists $args->{database_version} && !exists $args->{initial_version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"database_version"} and not exists $args->{"initial_version"} 7 0 7
Condition33%1/3
exists $args->{"database_version"} and not exists $args->{"initial_version"}
!ll&&!rl&&r
007
MC/DC0%0/2
exists $args->{"database_version"} and not exists $args->{"initial_version"}
exists $args->{"database_version"} not exists $args->{"initial_version"}
Truth table33%1/3
A and not(B)
A= exists $args->{"database_version"}B= not exists $args->{"initial_version"}
ABresult
0X0
100
111
70 7 return $args;
71 1 };
72  
73 sub next_version_set {
74 11 ▶ my $self = shift;
Subroutine next_version_set: called CC=3 SCAR=11.0
Pod undocumented
75 11 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_index_of_versions->{$self->to_version} < $self->_version_idx) { } 1 9 10
elsif ($self->_version_idx == $self->_index_of_versions->{$self->to_version}) { } 4 5 9
76 $self->_index_of_versions->{$self->to_version} <
77 $self->_version_idx
78 ) {
79 1 croak "you are trying to upgrade and your current version is greater\n".
80 "than the version you are trying to upgrade to. Either downgrade\n".
81 "or update your schema"
82 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
83 return undef
84 4 } else {
85 5 my $next_idx = $self->_inc_version_idx;
86 return [
87 5 $self->ordered_versions->[$next_idx - 1],
88 $self->ordered_versions->[$next_idx ],
89 ];
90 }
91 }
92  
93 sub previous_version_set {
94 7 ▶ my $self = shift;
Subroutine previous_version_set: called CC=3 SCAR=11.0
Pod undocumented
95 7 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_index_of_versions->{$self->to_version} > $self->_version_idx) { } 1 6 7
elsif ($self->_version_idx == $self->_index_of_versions->{$self->to_version}) { } 2 4 6
96 $self->_index_of_versions->{$self->to_version} >
97 $self->_version_idx
98 ) {
99 1 croak "you are trying to downgrade and your current version is less\n".
100 "than the version you are trying to downgrade to. Either upgrade\n".
101 "or update your schema"
102 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
103 return undef
104 2 } else {
105 4 my $next_idx = $self->_dec_version_idx;
106 return [
107 4 $self->ordered_versions->[$next_idx + 1],
108 $self->ordered_versions->[$next_idx ],
109 ];
110 }
111 }
112  
113 1 __PACKAGE__->meta->make_immutable;
114  
115 1 1;
116  
117 # vim: ts=2 sw=2 expandtab
118  
119 __END__
120  
121 =pod
122  
123 =head1 NAME
124  
125 DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions - Define your own list of versions to use for migrations
126  
127 =head1 SEE ALSO
128  
129 This class is an implementation of
130 L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
131 documentation is there.
132  
133 =head1 AUTHOR
134  
135 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
136  
137 =head1 COPYRIGHT AND LICENSE
138  
139 This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
140  
141 This is free software; you can redistribute it and/or modify it under
142 the same terms as the Perl 5 programming language system itself.
143  
144 =cut
« DeploymentHandler/Deprecated.pm ↑ Summary DeploymentHandler/VersionHandler/Monotonic.pm »