line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package DBIx::Migration::Directories::Base; |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
172
|
|
6
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
149
|
|
7
|
5
|
|
|
5
|
|
24
|
use Carp qw(croak); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
265
|
|
8
|
5
|
|
|
5
|
|
10588
|
use DBIx::Migration::Directories::Database; |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
5344
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $number = qr{[0-9]+(?:\.[0-9]+)?}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
return 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
21
|
|
|
21
|
1
|
55737
|
my($class, %args) = @_; |
16
|
21
|
|
|
|
|
165
|
($class, %args) = ($class->set_preinit_defaults(%args)); |
17
|
20
|
100
|
|
|
|
100
|
if(ref($class)) { |
18
|
9
|
|
|
|
|
23
|
$class = ref($class); |
19
|
|
|
|
|
|
|
} |
20
|
20
|
50
|
|
|
|
407
|
if(my $self = $class->driver_new(%args)) { |
21
|
20
|
|
|
|
|
101
|
$self->set_postinit_defaults(); |
22
|
15
|
|
|
|
|
275
|
return $self; |
23
|
|
|
|
|
|
|
} else { |
24
|
0
|
|
|
|
|
0
|
return; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub set_preinit_defaults { |
29
|
21
|
|
|
21
|
0
|
162
|
return(@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub set_postinit_defaults { |
33
|
20
|
|
|
20
|
0
|
39
|
my $self = shift; |
34
|
20
|
|
|
|
|
216
|
my $db = DBIx::Migration::Directories::Database->new(dbh => $self->{dbh}); |
35
|
19
|
|
|
|
|
271
|
$self->{db} = $db; |
36
|
19
|
|
|
|
|
63
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub db { |
40
|
126
|
|
|
126
|
0
|
213
|
my $self = shift; |
41
|
126
|
|
|
|
|
1074
|
return $self->{db}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub driver_new { |
45
|
20
|
|
|
20
|
0
|
88
|
my($class, %args) = @_; |
46
|
20
|
|
|
|
|
69
|
my $self = bless \%args, $class; |
47
|
20
|
|
|
|
|
125
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub read_file { |
51
|
40
|
|
|
40
|
1
|
347
|
my($self, $file) = @_; |
52
|
40
|
50
|
|
|
|
315
|
if(open(my $fh, '<', $file)) { |
53
|
40
|
|
|
|
|
1147404
|
my $data = join('', <$fh>); |
54
|
40
|
|
|
|
|
790
|
close($fh); |
55
|
40
|
|
|
|
|
698
|
return $data; |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
croak qq{open("$file") failed: $!}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub direction { |
62
|
111
|
|
|
111
|
1
|
192
|
my($self, $from, $to) = @_; |
63
|
111
|
|
|
|
|
533
|
return $to <=> $from; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub version_as_number { |
67
|
608
|
|
|
608
|
1
|
1119
|
my($self, $version) = @_; |
68
|
608
|
|
100
|
|
|
3988
|
return ($version || 0) + 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub versions { |
72
|
154
|
|
|
154
|
1
|
737
|
my($self, $string) = @_; |
73
|
154
|
100
|
|
|
|
3043
|
if($string =~ m{^($number)$}) { |
|
|
100
|
|
|
|
|
|
74
|
38
|
|
|
|
|
101
|
return($self->version_as_number(0), $self->version_as_number($1)); |
75
|
|
|
|
|
|
|
} elsif($string =~ m{^($number)-($number)$}) { |
76
|
100
|
|
|
|
|
397
|
return($self->version_as_number($1), $self->version_as_number($2)); |
77
|
|
|
|
|
|
|
} else { |
78
|
16
|
|
|
|
|
58
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub run_sql { |
83
|
20
|
|
|
20
|
1
|
1466
|
my($self, @sql) = @_; |
84
|
20
|
|
|
|
|
59
|
my $dbh = $self->{dbh}; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $dbh->transaction(sub { |
87
|
20
|
|
|
20
|
|
2161
|
my $marker = ''; |
88
|
20
|
|
|
|
|
40
|
my $good = 1; |
89
|
20
|
|
|
|
|
32
|
my $qn = 0; |
90
|
|
|
|
|
|
|
|
91
|
20
|
|
100
|
|
|
293
|
while($good && (my $query = shift(@sql))) { |
92
|
131
|
100
|
|
|
|
273
|
if(ref($query)) { |
93
|
36
|
|
|
|
|
86
|
$marker = $$query; |
94
|
36
|
|
|
|
|
187
|
$qn = 0; |
95
|
|
|
|
|
|
|
} else { |
96
|
95
|
|
|
|
|
110
|
$qn++; |
97
|
95
|
|
|
|
|
119
|
eval { $good = $dbh->do($query); }; |
|
95
|
|
|
|
|
365
|
|
98
|
|
|
|
|
|
|
|
99
|
95
|
50
|
|
|
|
27978
|
if($@) { |
|
|
100
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
die "[$marker#$qn]$@"; |
101
|
|
|
|
|
|
|
} elsif(!$good) { |
102
|
5
|
|
|
|
|
58
|
$dbh->set_err(undef, ''); |
103
|
5
|
|
50
|
|
|
166
|
$dbh->set_err( |
104
|
|
|
|
|
|
|
$dbh->err, |
105
|
|
|
|
|
|
|
join('', "[$marker#$qn] ", $dbh->errstr || ''), |
106
|
|
|
|
|
|
|
$dbh->state |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
20
|
|
|
|
|
103
|
return $good; |
113
|
20
|
|
|
|
|
320
|
}); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub require_schema { |
117
|
0
|
|
|
0
|
0
|
0
|
my($self, $schema, $version) = @_; |
118
|
0
|
|
|
|
|
0
|
my $schemas = $self->schemas; |
119
|
0
|
0
|
|
|
|
0
|
die qq{Schema "$schema" not installed!\n} |
120
|
|
|
|
|
|
|
unless($schemas->{$schema}); |
121
|
0
|
0
|
|
|
|
0
|
if($version) { |
122
|
0
|
0
|
|
|
|
0
|
die qq{Schema "$schema" is version $schemas->{$schema}{version}, we want $version.\n} |
123
|
|
|
|
|
|
|
unless($schemas->{$schema}{version} == $version); |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
0
|
return 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub schemas { |
129
|
6
|
|
|
6
|
1
|
3395
|
my $self = shift; |
130
|
6
|
|
|
|
|
23
|
return $self->db->db_schemas; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub schema_version_log { |
134
|
1
|
|
|
1
|
1
|
11115
|
my $self = shift; |
135
|
1
|
|
33
|
|
|
16
|
my $myschema = shift || $self->{schema} || |
136
|
|
|
|
|
|
|
croak "schema_version_log() called without a schema name"; |
137
|
1
|
|
|
|
|
6
|
return $self->db->db_schema_version_log($myschema); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |