line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::SimpleMigration::Client; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
661
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.0.2'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
1
|
|
|
1
|
0
|
251
|
my $self = bless {}, shift; |
9
|
1
|
50
|
|
|
|
6
|
return unless @_ % 2 == 0; |
10
|
1
|
|
|
|
|
3
|
my %args = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
4
|
$self->{dbh} = $args{dbh}; |
13
|
1
|
|
|
|
|
2
|
$self->{options} = $args{options}; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
4
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _create_migrations_table { |
19
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $query = ' |
22
|
1
|
|
|
|
|
5
|
CREATE TABLE IF NOT EXISTS ' . $self->{options}->{migrations_table} . ' ( |
23
|
|
|
|
|
|
|
name varchar(255) primary key not null, |
24
|
|
|
|
|
|
|
applied datetime not null |
25
|
|
|
|
|
|
|
) |
26
|
|
|
|
|
|
|
'; |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
6
|
$self->{dbh}->do($query) or croak __PACKAGE__ . ': Error creating table: ' . $self->{dbh}->errstr; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
180
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _migrations_table_exists { |
34
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
return 0; # checking seems to be largely driver-dependent |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _lock_migrations_table { |
40
|
2
|
|
|
2
|
|
4
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
10
|
return 1; # to be overloaded per-DB |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _applied_migrations { |
46
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $query = ' |
49
|
|
|
|
|
|
|
SELECT name, applied |
50
|
1
|
|
|
|
|
3
|
FROM ' . $self->{options}->{migrations_table}; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
14
|
my $result = $self->{dbh}->selectall_arrayref($query, {Slice => {}}); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
131
|
my %applied_migrations; |
55
|
1
|
|
|
|
|
2
|
foreach my $row (@{$result}) { |
|
1
|
|
|
|
|
3
|
|
56
|
0
|
|
|
|
|
0
|
$applied_migrations{$row->{name}} = $row->{applied}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
return \%applied_migrations; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _insert_migration { |
63
|
2
|
|
|
2
|
|
5
|
my ($self, $key) = @_; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
3
|
eval { |
66
|
2
|
|
|
|
|
8
|
my $query = 'INSERT INTO ' . $self->{options}->{migrations_table} . ' (name, applied) VALUES (?, CURRENT_TIMESTAMP)'; |
67
|
2
|
|
|
|
|
13
|
my $sth = $self->{dbh}->prepare($query); |
68
|
2
|
|
|
|
|
353
|
$sth->execute($key); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
9
|
if ($@) { |
72
|
0
|
|
|
|
|
0
|
carp __PACKAGE__ . ': Error recording migration: ' . $self->{dbh}->errstr; |
73
|
0
|
|
|
|
|
0
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
9
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |