lib/DBIx/Class/DeploymentAdapter.pm

filter: Statementstmt 28.3% 17 / 60 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 45.4% 5 / 11 Podpod 66.6% 4 / 6 totaltotal 22.8% 26 / 114 CC 16 SCAR 34.6
CC
16
Cov
19%
dh
56.0
upgrade_incremental
56.0
install
6.0
CRAP 31.8
↑ Summary blib/lib/DBIx/Class/DeploymentAdapter.pm »
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.07";
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 sub dh {
46  
47 0 ▶ my ( $self, $args ) = @_;
Subroutine dh: not called CC=7 SCAR=40.3
Pod undocumented
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 sub BUILD {
66  
67 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
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 sub install {
82  
83 0 ▶ my ( $self ) = @_;
Subroutine install: not called CC=2 SCAR=17.9
Pod documented
84  
85 0 ▶ return unless $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dh 0 0 0
86  
87 0 $self->dh->install;
88 }
89  
90 =head2 prepare
91  
92 Summarize all prepares from L<DBIx::Class::DeploymentHandler> in one Command
93  
94 $da->prepare;
95  
96 =cut
97  
98 sub prepare {
99  
100 0 ▶ my ($self) = @_;
Subroutine prepare: not called CC=2 SCAR=17.9
Pod documented
101  
102 0 ▶ return unless $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dh 0 0 0
103  
104 0 my $start_version = $self->dh->database_version;
105 0 my $target_version = $self->dh->schema->schema_version;
106  
107 0 $self->dh->prepare_install;
108  
109 0 $self->dh->prepare_upgrade(
110 {
111 from_version => $start_version,
112 to_version => $target_version,
113 }
114 );
115  
116 0 $self->dh->prepare_downgrade(
117 {
118 from_version => $target_version,
119 to_version => $start_version,
120 }
121 );
122 }
123  
124 =head2 status
125  
126 Returns the Status of database and schema versions as string
127  
128 $da->status;
129  
130 =cut
131  
132 sub status {
133  
134 0 ▶ my ( $self ) = @_;
Subroutine status: not called CC=2 SCAR=17.9
Pod documented
135  
136 0 ▶ return unless ref $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->dh 0 0 0
137  
138 0 my $deployed_version = $self->dh->database_version;
139 0 my $schema_version = $self->dh->schema->schema_version;
140  
141 0 return sprintf( "Schema is %s\nDeployed database is %s\n", $schema_version, $deployed_version );
142  
143 }
144  
145 =head2 upgrade_incremental
146  
147 Upgrade the database version step by step, if anything wents wrong, it dies with the specific database error.
148  
149 You can give a target version to the method to make it stop there
150  
151 $da->upgrade_incremental;
152 $da->upgrade_incremental(112);
153  
154 =cut
155  
156 sub upgrade_incremental {
157  
158 0 ▶ my ( $self, $to_version ) = @_;
Subroutine upgrade_incremental: not called CC=7 SCAR=40.3
Pod documented
159  
160 0 ▶ return unless $self->dh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dh 0 0 0
161  
162 0 my $start_version = $self->dh->database_version + 1;
163 0 my $target_version = $self->dh->schema->schema_version;
164  
165 0 for my $version ( $start_version .. $target_version ) {
166  
167 0 ▶ if( $to_version && $version >= $to_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_version and $version >= $to_version) 0 0 0
Condition0%0/3
$to_version and $version >= $to_version
!ll&&!rl&&r
000
MC/DC0%0/2
$to_version and $version >= $to_version
$to_version $version >= $to_version
Truth table0%0/3
A and B
A= $to_versionB= $version >= $to_version
ABresult
0X0
100
111
168 0 next;
169 }
170  
171 0 warn "upgrading to version $version\n";
172  
173 0 eval {
174 0 ▶ my ( $ddl, $sql ) = @{ $self->dh->upgrade_single_step( { version_set => [ $version - 1, $version ] } ) || [] }; # from last version to desired version
Branch: 1 branch
BranchTrueFalseTotal
$self->dh->upgrade_single_step({"version_set", [$version - 1, $version]}) or [] 0 0 0
175 0 $self->dh->add_database_version(
176 {
177 version => $version,
178 ddl => $ddl,
179 upgrade_sql => $sql,
180 }
181 );
182 };
183  
184 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
185 0 my $error_version = $self->dh->database_version;
186 0 warn "Database remains on version $error_version";
187 0 die "UPGRADE ERROR - Version $error_version upgrading to $version: " . $@;
188 }
189 }
190 }
191  
192 1 1;
193  
194  
195  
196 =head1 LICENSE
197  
198 Copyright (C) Patrick Kilter.
199  
200 This library is free software; you can redistribute it and/or modify
201 it under the same terms as Perl itself.
202  
203 =head1 AUTHOR
204  
205 Patrick Kilter E<lt>pk@gassmann.itE<gt>
206  
207 =cut
↑ Summary blib/lib/DBIx/Class/DeploymentAdapter.pm »