lib/DBIx/SchemaChecksum/Driver/Pg.pm

filter: Statementstmt 21.5% 14 / 65 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod n/a totaltotal 18.2% 17 / 93 CC 11 SCAR 29.0
CC
11
Cov
16%
__ANON__
42.0
__ANON__
12.0
__ANON__
6.0
CRAP 18.2
« lib/DBIx/SchemaChecksum/App/ApplyChanges.pm ↑ Summary lib/DBIx/SchemaChecksum.pm »
1 package DBIx::SchemaChecksum::Driver::Pg;
2  
3 # ABSTRACT: Pg driver for DBIx::SchemaChecksum
4 1 our $VERSION = '1.106'; # VERSION
5  
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶around '_build_schemadump_column' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
11 0 my $orig = shift;
12 0 my ($self,$schema,$table,$column,$data) = @_;
13  
14 0 my $relevants = $self->$orig($schema,$table,$column,$data);
15  
16 # add postgres enums
17 0 ▶ if ( $data->{pg_enum_values} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"pg_enum_values"}) 0 0 0
18 0 $relevants->{pg_enum_values} = $data->{pg_enum_values};
19 }
20  
21 0 return $relevants;
22 1 };
23  
24 0 ▶around '_build_schemadump_table' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
25 0 my $orig = shift;
26 0 my ($self,$schema,$table) = @_;
27  
28 0 my $dbh = $self->dbh;
29  
30 0 my $relevants = $self->$orig($schema,$table);
31  
32 # Indexes
33 {
34 0 my $sth_indexes = $dbh->prepare(q[SELECT indexdef
35 FROM pg_catalog.pg_indexes
36 WHERE schemaname=?
37 AND tablename=?]);
38  
39 0 $sth_indexes->execute($schema, $table);
40  
41 0 my @indexes;
42 0 ▶ while (my ($index) = $sth_indexes->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($index) = $sth_indexes->fetchrow_array) 0 0 0
43 0 $index=~s/$schema\.//g;
44 0 push(@indexes,$index);
45 }
46  
47 0 @indexes = sort (@indexes);
48 $relevants->{indexes} = \@indexes
49 0 ▶ if @indexes;
Branch: 1 branch
BranchTrueFalseTotal
if @indexes 0 0 0
50 }
51  
52 # Triggers
53 0 ▶ if ($self->driveropts->{triggers}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->driveropts->{"triggers"}) 0 0 0
54 0 my $sth_triggers = $dbh->prepare(q[SELECT pg_get_triggerdef(x.oid)
55 FROM pg_catalog.pg_trigger x
56 JOIN pg_catalog.pg_class c ON c.oid = x.tgrelid
57 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
58 WHERE c.relkind = 'r'::"char"
59 AND x.tgisinternal = FALSE
60 AND n.nspname = ?
61 AND c.relname = ?]);
62  
63 0 $sth_triggers->execute($schema, $table);
64  
65 0 my @triggers;
66 0 ▶ while (my ($index) = $sth_triggers->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($index) = $sth_triggers->fetchrow_array) 0 0 0
67 0 $index=~s/$schema\.//g;
68 0 push(@triggers,$index);
69 }
70  
71 0 @triggers = sort (@triggers);
72 $relevants->{triggers} = \@triggers
73 0 ▶ if @triggers;
Branch: 1 branch
BranchTrueFalseTotal
if @triggers 0 0 0
74 }
75  
76 0 return $relevants;
77 1 };
78  
79 0 ▶around '_build_schemadump_schema' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 0 my $orig = shift;
81 0 my ($self,$schema) = @_;
82  
83 0 my $relevants = $self->$orig($schema);
84 0 ▶ $relevants->{sequences} = $self->_build_schemadump_sequences($schema) if $self->driveropts->{sequences};
Branch: 1 branch
BranchTrueFalseTotal
if $self->driveropts->{"sequences"} 0 0 0
85 0 ▶ $relevants->{functions} = $self->_build_schemadump_functions($schema) if $self->driveropts->{functions};
Branch: 1 branch
BranchTrueFalseTotal
if $self->driveropts->{"functions"} 0 0 0
86  
87 0 return $relevants;
88 1 };
89  
90 0 ▶sub _build_schemadump_sequences {
Subroutine _build_schemadump_sequences: not called CC=2 SCAR=17.9
91 0 my ($self,$schema) = @_;
92  
93 0 my $dbh = $self->dbh;
94 # TODO introspect increment, min, max, cache and cycle
95 0 my $sth_sequences = $dbh->prepare(q[SELECT c.relname
96 FROM pg_catalog.pg_class c
97 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
98 WHERE c.relkind = 'S'::"char"
99 AND n.nspname LIKE ?
100 AND n.nspname <> 'pg_catalog'
101 ORDER BY 1]);
102  
103 0 $sth_sequences->execute($schema);
104  
105 0 my @sequences;
106 0 ▶ while (my ($index) = $sth_sequences->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($index) = $sth_sequences->fetchrow_array) 0 0 0
107 0 push(@sequences,$index);
108 }
109  
110 0 return \@sequences;
111 };
112  
113 0 ▶sub _build_schemadump_functions {
Subroutine _build_schemadump_functions: not called CC=2 SCAR=17.9
114 0 my ($self,$schema) = @_;
115  
116 0 my $dbh = $self->dbh;
117  
118 # TODO handle aggregate and windowing functions
119 0 my $sth_functions = $dbh->prepare(q[SELECT n.nspname, x.proname, pg_get_functiondef(x.oid)
120 FROM pg_catalog.pg_proc x
121 LEFT JOIN pg_namespace n ON n.oid = x.pronamespace
122 WHERE proisagg = FALSE
123 AND proiswindow = FALSE
124 AND n.nspname LIKE ?
125 AND n.nspname <> 'pg_catalog'
126 ORDER BY 1]);
127  
128 0 $sth_functions->execute($schema);
129
130 0 my %functions;
131 0 ▶ while (my ($this_schema,$name,$definition) = $sth_functions->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth_functions->fetchrow_array) 0 0 0
132 0 $functions{$this_schema.'.'.$name} = $definition;
133 }
134
135 0 return \%functions
136 };
137  
138 1 1;
139  
140 __END__
« lib/DBIx/SchemaChecksum/App/ApplyChanges.pm ↑ Summary lib/DBIx/SchemaChecksum.pm »