line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ActiveRecord::Simple::Migration; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
55212
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
14
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
280
|
my ($name, $num) = @_; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
33
|
|
|
4
|
$num ||= time(); |
12
|
|
|
|
|
|
|
|
13
|
1
|
50
|
|
|
|
87
|
open my $fh_up, ">", "$num-UP.sql" or return; |
14
|
1
|
|
|
|
|
3
|
say {$fh_up} "--- Migration #$num, `$name`, UP"; |
|
1
|
|
|
|
|
9
|
|
15
|
1
|
|
|
|
|
49
|
close $fh_up; |
16
|
|
|
|
|
|
|
|
17
|
1
|
50
|
|
|
|
33
|
open my $fh_dn, ">", "$num-DN.sql" or return; |
18
|
1
|
|
|
|
|
3
|
say {$fh_dn} "--- Migration #$num, `$name`. DOWN"; |
|
1
|
|
|
|
|
5
|
|
19
|
1
|
|
|
|
|
17
|
close $fh_dn; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
8
|
return 1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub down { |
25
|
1
|
|
|
1
|
0
|
918
|
my ($dbh, $num) = @_; |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
33
|
|
|
6
|
$dbh && $num or return; |
28
|
1
|
50
|
|
|
|
4
|
my $sql = _slurp_file("$num-DN.sql") or return; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
return $dbh->do($sql); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub up { |
34
|
1
|
|
|
1
|
0
|
3
|
my ($dbh, $num) = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
33
|
|
|
6
|
$dbh && $num or return; |
37
|
1
|
50
|
|
|
|
3
|
my $sql = _slurp_file("$num-UP.sql") or return; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
7
|
return $dbh->do($sql); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _slurp_file { |
43
|
2
|
|
|
2
|
|
5
|
my ($file_path) = @_; |
44
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
17
|
return if !-e $file_path; |
46
|
2
|
|
|
|
|
30
|
open my $fh, "$file_path"; |
47
|
2
|
|
|
|
|
5
|
my $text = do { local $/; <$fh> }; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
24
|
|
48
|
2
|
|
|
|
|
10
|
close $fh; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
11
|
return $text; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |