blib/lib/DBIx/SimpleMigration/Client.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 78.2% 36 / 46 CC 5 SCAR 6.5
CC
5
Cov
79%
_insert_migration
2.1
_create_migrations_table
2.0
new
2.0
CRAP 1.9
« blib/lib/DBIx/SimpleMigration/Migration.pm ↑ Summary blib/lib/DBIx/SimpleMigration/Client/SQLite.pm »
1 package DBIx::SimpleMigration::Client;
2  
3 2 our $VERSION = '1.0.1';
4  
5 sub new {
6 1 ▶ my $self = bless {}, shift;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
7 1 ▶ return unless @_ % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ % 2 == 0 0 1 1
8 1 my %args = @_;
9  
10 1 $self->{dbh} = $args{dbh};
11 1 $self->{options} = $args{options};
12  
13 1 return $self;
14 }
15  
16 sub _create_migrations_table {
17 1 ▶ my ($self) = @_;
Subroutine _create_migrations_table: called CC=2 SCAR=7.0
18  
19 my $query = '
20 1 CREATE TABLE IF NOT EXISTS ' . $self->{options}->{migrations_table} . ' (
21 name varchar(255) primary key not null,
22 applied datetime not null
23 )
24 ';
25  
26 1 ▶ $self->{dbh}->do($query) or die 'Error creating table: ' . $self->{dbh}->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"dbh"}->do($query) or die 'Error creating table: ' . $self->{"dbh"}->errstr 0 1 1
27  
28 1 return $self;
29 }
30  
31 sub _migrations_table_exists {
32 0 ▶ my ($self) = @_;
Subroutine _migrations_table_exists: not called CC=1 SCAR=6.9
33  
34 0 return 0; # checking seems to be largely driver-dependent
35 }
36  
37 sub _lock_migrations_table {
38 2 ▶ my ($self) = @_;
Subroutine _lock_migrations_table: called CC=1 SCAR=0.0
39  
40 2 return 1; # to be overloaded per-DB
41 }
42  
43 sub _applied_migrations {
44 1 ▶ my ($self) = @_;
Subroutine _applied_migrations: called CC=2 SCAR=7.0
45  
46 my $query = '
47 SELECT name, applied
48 1 FROM ' . $self->{options}->{migrations_table};
49  
50 1 my $result = $self->{dbh}->selectall_arrayref($query, {Slice => {}});
51  
52 1 my %applied_migrations;
53 1 foreach my $row (@{$result}) {
54 0 $applied_migrations{$row->{name}} = $row->{applied};
55 }
56  
57 1 return \%applied_migrations;
58 }
59  
60 sub _insert_migration {
61 2 ▶ my ($self, $key) = @_;
Subroutine _insert_migration: called CC=2 SCAR=7.3
62  
63 2 eval {
64 2 my $query = 'INSERT INTO ' . $self->{options}->{migrations_table} . ' (name, applied) VALUES (?, CURRENT_TIMESTAMP)';
65 2 my $sth = $self->{dbh}->prepare($query);
66 2 $sth->execute($key);
67 };
68  
69 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
70 0 warn 'Error recording migration: ' . $self->{dbh}->errstr;
71 0 return;
72 }
73  
74 2 return 1;
75 }
76  
77 2 1;
78  
79 __END__
« blib/lib/DBIx/SimpleMigration/Migration.pm ↑ Summary blib/lib/DBIx/SimpleMigration/Client/SQLite.pm »