line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::DeploymentAdapter; |
2
|
1
|
|
|
1
|
|
484
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
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
|
|
|
1
|
|
332
|
use DBIx::Class::DeploymentHandler; |
|
1
|
|
|
|
|
1249000
|
|
|
1
|
|
|
|
|
34
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
8
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has dh_store => ( |
41
|
|
|
|
|
|
|
is => "rw", |
42
|
|
|
|
|
|
|
isa => "Maybe[Object]" |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub dh { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
0
|
|
my ( $self, $args ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( !$self->dh_store ) { |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
0
|
|
|
|
return unless $args && $args->{schema}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
0
|
|
|
|
$args->{script_directory} ||= "./share/migrations"; |
54
|
0
|
|
0
|
|
|
|
$args->{databases} ||= ["MySQL"]; |
55
|
0
|
|
0
|
|
|
|
$args->{sql_translator_args} ||= { mysql_enable_utf8 => 1 }; |
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
|
|
|
0
|
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
|
|
|
|
|
|
|
sub install { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my @params = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
return unless $self->dh; |
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
|
|
|
|
|
|
|
sub prepare { |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
return unless $self->dh; |
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
|
|
|
|
|
|
|
sub status { |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
return unless ref $self->dh; |
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
|
|
|
|
|
|
|
sub upgrade_incremental { |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
0
|
1
|
|
my ( $self, $to_version ) = @_; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
unless ( $self->dh ) { |
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
|
0
|
0
|
|
|
|
if ( $to_version && $upgrade_version > $to_version ) { |
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
|
0
|
|
|
|
|
my ( $ddl, $sql ) = @{ $self->dh->upgrade_single_step( { version_set => [ $version, $upgrade_version ] } ) || [] }; # from last version to desired version |
|
0
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if ($@) { |
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; |
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 |