lib/DBIx/Class/DeploymentAdapter.pm

filter: Statementstmt 25.7% 17 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 45.4% 5 / 11 Podpod 66.6% 4 / 6 totaltotal 21.4% 26 / 121 CC 16 SCAR 34.6
CC
16
Cov
18%
dh
56.0
upgrade_incremental
56.0
install
6.0
CRAP 31.8
↑ Summary
1 package DBIx::Class::DeploymentAdapter;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = "0.09";
7  
8 =encoding utf-8
9  
10 =head1 NAME
11  
12 DBIx::Class::DeploymentAdapter - Deployment handler adapter to your DBIC app, which offers some candy
13  
14 =head1 SYNOPSIS
15  
16 use DBIx::Class::DeploymentAdapter;
17  
18 my $args = {
19 schema => $schema,
20 script_directory => './share/migrations',
21 databases => ['MySQL'],
22 sql_translator_args => { mysql_enable_utf8 => 1 },
23 };
24  
25 $args->{to_version} = $to_version if $to_version;
26 $args->{force_overwrite} = $force_overwrite if $force_overwrite;
27  
28 my $da = DBIx::Class::DeploymentAdapter->new($args);
29  
30 =head1 DESCRIPTION
31  
32 Deployment handler adapter to your DBIC app, which offers some candy
33  
34 =cut
35  
36 1 ▶use DBIx::Class::DeploymentHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 has dh_store => (
41 is => "rw",
42 isa => "Maybe[Object]"
43 );
44  
45 0 ▶sub dh {
Subroutine dh: not called CC=7 SCAR=40.3
Pod undocumented
46  
47 0 my ( $self, $args ) = @_;
48  
49 0 ▶ if ( !$self->dh_store ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dh_store) 0 0 0
50  
51 0 ▶ return unless $args && $args->{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless $args and $args->{"schema"} 0 0 0
Condition0%0/3
$args and $args->{"schema"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args and $args->{"schema"}
$args $args->{"schema"}
Truth table0%0/3
A and B
A= $argsB= $args->{"schema"}
ABresult
0X0
100
111
52  
53 0 ▶ $args->{script_directory} ||= "./share/migrations";
Condition0%0/2
$args->{"script_directory"} ||= "./share/migrations"
l!l
00
MC/DC0%0/1
$args->{"script_directory"} ||= "./share/migrations"
$args->{"script_directory"}
Truth table0%0/2
A
A= $args->{"script_directory"}
Aresult
11
00
54 0 ▶ $args->{databases} ||= ["MySQL"];
Condition0%0/2
$args->{"databases"} ||= ["MySQL"]
l!l
00
MC/DC0%0/1
$args->{"databases"} ||= ["MySQL"]
$args->{"databases"}
Truth table0%0/2
A
A= $args->{"databases"}
Aresult
11
00
55 0 ▶ $args->{sql_translator_args} ||= { mysql_enable_utf8 => 1 };
Condition0%0/2
$args->{"sql_translator_args"} ||= {"mysql_enable_utf8", 1}
l!l
00
MC/DC0%0/1
$args->{"sql_translator_args"} ||= {"mysql_enable_utf8", 1}
$args->{"sql_translator_args"}
Truth table0%0/2
A
A= $args->{"sql_translator_args"}
Aresult
11
00
56  
57 0 my $dh = DBIx::Class::DeploymentHandler->new($args);
58 0 $self->dh_store($dh);
59  
60 }
61  
62 0 return $self->dh_store;
63 }
64  
65 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 0 my $self = shift;
68 0 my $args = shift;
69  
70 0 $self->dh($args);
71 }
72  
73 =head2 install
74  
75 Installs the schema files to the given Database
76  
77 $da->install;
78  
79 =cut
80  
81 0 ▶sub install {
Subroutine install: not called CC=2 SCAR=17.9
Pod documented
82  
83 0 my $self = shift;
84 0 my @params = @_;
85  
86 0 ▶ return unless $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dh 0 0 0
87  
88 0 $self->dh->install(@params);
89 }
90  
91 =head2 prepare
92  
93 Summarize all prepares from L<DBIx::Class::DeploymentHandler> in one Command
94  
95 $da->prepare;
96  
97 =cut
98  
99 0 ▶sub prepare {
Subroutine prepare: not called CC=2 SCAR=17.9
Pod documented
100  
101 0 my ($self) = @_;
102  
103 0 ▶ return unless $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dh 0 0 0
104  
105 0 my $start_version = $self->dh->database_version;
106 0 my $target_version = $self->dh->schema->schema_version;
107  
108 0 $self->dh->prepare_install;
109  
110 0 $self->dh->prepare_upgrade(
111 {
112 from_version => $start_version,
113 to_version => $target_version,
114 }
115 );
116  
117 0 $self->dh->prepare_downgrade(
118 {
119 from_version => $target_version,
120 to_version => $start_version,
121 }
122 );
123 }
124  
125 =head2 status
126  
127 Returns the Status of database and schema versions as string
128  
129 $da->status;
130  
131 =cut
132  
133 0 ▶sub status {
Subroutine status: not called CC=2 SCAR=17.9
Pod documented
134  
135 0 my ($self) = @_;
136  
137 0 ▶ return unless ref $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->dh 0 0 0
138  
139 0 my $deployed_version = $self->dh->database_version;
140 0 my $schema_version = $self->dh->schema->schema_version;
141  
142 0 return sprintf( "Schema is %s\nDeployed database is %s\n", $schema_version, $deployed_version );
143  
144 }
145  
146 =head2 upgrade_incremental
147  
148 Upgrade the database version step by step, if anything wents wrong, it dies with the specific database error.
149  
150 You can give a target version to the method to make it stop there
151  
152 $da->upgrade_incremental;
153 $da->upgrade_incremental(112);
154  
155 =cut
156  
157 0 ▶sub upgrade_incremental {
Subroutine upgrade_incremental: not called CC=7 SCAR=40.3
Pod documented
158  
159 0 my ( $self, $to_version ) = @_;
160  
161 0 ▶ unless ( $self->dh ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dh) 0 0 0
162  
163 0 warn "Missing dh-handler";
164 0 return;
165 }
166  
167 0 my $start_version = $self->dh->database_version;
168 0 my $target_version = $self->dh->schema->schema_version;
169  
170 0 warn "Try to upgrade from $start_version to $target_version";
171  
172 0 for my $upgrade_version ( ( $start_version + 1 ) .. $target_version ) {
173  
174 0 my $version = $self->dh->database_version;
175  
176 0 ▶ if ( $to_version && $upgrade_version > $to_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_version and $upgrade_version > $to_version) 0 0 0
Condition0%0/3
$to_version and $upgrade_version > $to_version
!ll&&!rl&&r
000
MC/DC0%0/2
$to_version and $upgrade_version > $to_version
$to_version $upgrade_version > $to_version
Truth table0%0/3
A and B
A= $to_versionB= $upgrade_version > $to_version
ABresult
0X0
100
111
177 0 warn "skip version $upgrade_version";
178 0 next;
179 }
180  
181 0 warn "upgrading to version $upgrade_version";
182  
183 0 eval {
184 0 ▶ my ( $ddl, $sql ) = @{ $self->dh->upgrade_single_step( { version_set => [ $version, $upgrade_version ] } ) || [] }; # from last version to desired version
Condition0%0/2
$self->dh->upgrade_single_step({'version_set', [$version, $upgrade_version]}) || []
l!l
00
MC/DC0%0/1
$self->dh->upgrade_single_step({'version_set', [$version, $upgrade_version]}) || []
$self->dh->upgrade_single_step({'version_set', [$version, $upgrade_version]})
Truth table0%0/2
A
A= $self->dh->upgrade_single_step({'version_set', [$version, $upgrade_version]})
Aresult
11
00
185 0 $self->dh->add_database_version(
186 {
187 version => $upgrade_version,
188 ddl => $ddl,
189 upgrade_sql => $sql,
190 }
191 );
192 };
193  
194 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
195 0 my $error_version = $self->dh->database_version;
196 0 warn "Database remains on version $error_version";
197 0 die "UPGRADE ERROR - Version $error_version upgrading to $upgrade_version: " . $@;
198 }
199 }
200 }
201  
202 1 1;
203  
204 =head1 LICENSE
205  
206 Copyright (C) Jens Gassmann Software-Entwicklung.
207  
208 This library is free software; you can redistribute it and/or modify
209 it under the same terms as Perl itself.
210  
211 =head1 AUTHOR
212  
213 Patrick Kilter E<lt>pk@gassmann.itE<gt>
214 Jens Gassmann E<lt>jg@gassmann.itE<gt>
215  
216 =cut
↑ Summary