line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::SimpleMigration::Migration; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
23
|
use 5.10.0; |
|
2
|
|
|
|
|
6
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
5
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
88
|
|
8
|
2
|
|
|
2
|
|
6
|
use File::Basename; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
629
|
|
9
|
2
|
|
|
2
|
|
972
|
use SQL::SplitStatement; |
|
2
|
|
|
|
|
166182
|
|
|
2
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.0.2'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
2
|
|
|
2
|
0
|
8
|
my $self = bless {}, shift; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
11
|
return unless @_ % 2 == 0; |
17
|
2
|
|
|
|
|
10
|
my %args = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
croak __PACKAGE__ . '->new: file option missing or does not exist' |
20
|
2
|
50
|
33
|
|
|
56
|
unless ($args{file} && -f $args{file}); |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
8
|
croak __PACKAGE__ . '->new: client missing' unless $args{client}; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
10
|
$self->{_client} = $args{client}; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
33
|
($self->{_key}) = fileparse($args{file}); |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
4
|
my $contents; |
29
|
|
|
|
|
|
|
{ |
30
|
2
|
|
|
|
|
3
|
local $/ = undef; |
|
2
|
|
|
|
|
13
|
|
31
|
2
|
50
|
|
|
|
76
|
open FH, '<', $args{file} or croak __PACKAGE__ . '->new: Error opening file: ' . $!; |
32
|
2
|
|
|
|
|
58
|
$contents = ; |
33
|
2
|
|
|
|
|
24
|
close FH; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
18
|
my $splitter = SQL::SplitStatement->new; |
37
|
2
|
|
|
|
|
81
|
my @statements = $splitter->split($contents); |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
3885
|
$self->{_statements} = \@statements; |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
17
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub apply { |
45
|
2
|
|
|
2
|
0
|
2
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
450
|
say 'Applying ' . $self->{_key}; |
48
|
|
|
|
|
|
|
|
49
|
2
|
50
|
|
|
|
20
|
if (!$self->{_client}->_lock_migrations_table) { |
50
|
0
|
|
|
|
|
0
|
die 'Error acquiring table lock'; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
4
|
eval { |
54
|
2
|
|
|
|
|
4
|
foreach my $query (@{$self->{_statements}}) { |
|
2
|
|
|
|
|
8
|
|
55
|
2
|
|
|
|
|
25
|
$self->{_client}->{dbh}->do($query) |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
2
|
50
|
|
|
|
732
|
if ($@) { |
60
|
0
|
0
|
|
|
|
0
|
$self->{_client}->{dbh}->rollback or croak __PACKAGE__ . '->apply: Error rolling back transaction: ' . $self->{_client}->{dbh}->errstr; |
61
|
0
|
|
|
|
|
0
|
croak __PACKAGE__ . '->apply: Error applying changeset'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
2
|
50
|
|
|
|
16
|
if (!$self->{_client}->_insert_migration($self->{_key})) { |
65
|
0
|
|
|
|
|
0
|
$self->{_client}->{dbh}->rollback; |
66
|
0
|
|
|
|
|
0
|
croak; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
119050
|
$self->{_client}->{dbh}->commit; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |