line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::SchemaChecksum::Driver::Pg; |
2
|
1
|
|
|
1
|
|
1316
|
use utf8; |
|
1
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
28
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Pg driver for DBIx::SchemaChecksum |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
34
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
67
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
around '_build_schemadump_column' => sub { |
10
|
|
|
|
|
|
|
my $orig = shift; |
11
|
|
|
|
|
|
|
my ($self,$schema,$table,$column,$data) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $relevants = $self->$orig($schema,$table,$column,$data); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# add postgres enums |
16
|
|
|
|
|
|
|
if ( $data->{pg_enum_values} ) { |
17
|
|
|
|
|
|
|
$relevants->{pg_enum_values} = $data->{pg_enum_values}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return $relevants; |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
around '_build_schemadump_table' => sub { |
24
|
|
|
|
|
|
|
my $orig = shift; |
25
|
|
|
|
|
|
|
my ($self,$schema,$table) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $dbh = $self->dbh; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $relevants = $self->$orig($schema,$table); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Indexes |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
my $sth_indexes = $dbh->prepare(q[SELECT indexdef |
34
|
|
|
|
|
|
|
FROM pg_catalog.pg_indexes |
35
|
|
|
|
|
|
|
WHERE schemaname=? |
36
|
|
|
|
|
|
|
AND tablename=?]); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$sth_indexes->execute($schema, $table); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @indexes; |
41
|
|
|
|
|
|
|
while (my ($index) = $sth_indexes->fetchrow_array) { |
42
|
|
|
|
|
|
|
$index=~s/$schema\.//g; |
43
|
|
|
|
|
|
|
push(@indexes,$index); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
@indexes = sort (@indexes); |
47
|
|
|
|
|
|
|
$relevants->{indexes} = \@indexes |
48
|
|
|
|
|
|
|
if @indexes; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Triggers |
52
|
|
|
|
|
|
|
if ($self->driveropts->{triggers}) { |
53
|
|
|
|
|
|
|
my $sth_triggers = $dbh->prepare(q[SELECT pg_get_triggerdef(x.oid) |
54
|
|
|
|
|
|
|
FROM pg_catalog.pg_trigger x |
55
|
|
|
|
|
|
|
JOIN pg_catalog.pg_class c ON c.oid = x.tgrelid |
56
|
|
|
|
|
|
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
57
|
|
|
|
|
|
|
WHERE c.relkind = 'r'::"char" |
58
|
|
|
|
|
|
|
AND x.tgisinternal = FALSE |
59
|
|
|
|
|
|
|
AND n.nspname = ? |
60
|
|
|
|
|
|
|
AND c.relname = ?]); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$sth_triggers->execute($schema, $table); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my @triggers; |
65
|
|
|
|
|
|
|
while (my ($index) = $sth_triggers->fetchrow_array) { |
66
|
|
|
|
|
|
|
$index=~s/$schema\.//g; |
67
|
|
|
|
|
|
|
push(@triggers,$index); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
@triggers = sort (@triggers); |
71
|
|
|
|
|
|
|
$relevants->{triggers} = \@triggers |
72
|
|
|
|
|
|
|
if @triggers; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $relevants; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
around '_build_schemadump_schema' => sub { |
79
|
|
|
|
|
|
|
my $orig = shift; |
80
|
|
|
|
|
|
|
my ($self,$schema) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $relevants = $self->$orig($schema); |
83
|
|
|
|
|
|
|
$relevants->{sequences} = $self->_build_schemadump_sequences($schema) if $self->driveropts->{sequences}; |
84
|
|
|
|
|
|
|
$relevants->{functions} = $self->_build_schemadump_functions($schema) if $self->driveropts->{functions}; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $relevants; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _build_schemadump_sequences { |
90
|
0
|
|
|
0
|
|
|
my ($self,$schema) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $dbh = $self->dbh; |
93
|
|
|
|
|
|
|
# TODO introspect increment, min, max, cache and cycle |
94
|
0
|
|
|
|
|
|
my $sth_sequences = $dbh->prepare(q[SELECT c.relname |
95
|
|
|
|
|
|
|
FROM pg_catalog.pg_class c |
96
|
|
|
|
|
|
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
97
|
|
|
|
|
|
|
WHERE c.relkind = 'S'::"char" |
98
|
|
|
|
|
|
|
AND n.nspname LIKE ? |
99
|
|
|
|
|
|
|
AND n.nspname <> 'pg_catalog' |
100
|
|
|
|
|
|
|
ORDER BY 1]); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$sth_sequences->execute($schema); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my @sequences; |
105
|
0
|
|
|
|
|
|
while (my ($index) = $sth_sequences->fetchrow_array) { |
106
|
0
|
|
|
|
|
|
push(@sequences,$index); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return \@sequences; |
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _build_schemadump_functions { |
113
|
0
|
|
|
0
|
|
|
my ($self,$schema) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $dbh = $self->dbh; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# TODO handle aggregate and windowing functions |
118
|
0
|
|
|
|
|
|
my $sth_functions = $dbh->prepare(q[SELECT n.nspname, x.proname, pg_get_functiondef(x.oid) |
119
|
|
|
|
|
|
|
FROM pg_catalog.pg_proc x |
120
|
|
|
|
|
|
|
LEFT JOIN pg_namespace n ON n.oid = x.pronamespace |
121
|
|
|
|
|
|
|
WHERE proisagg = FALSE |
122
|
|
|
|
|
|
|
AND proiswindow = FALSE |
123
|
|
|
|
|
|
|
AND n.nspname LIKE ? |
124
|
|
|
|
|
|
|
AND n.nspname <> 'pg_catalog' |
125
|
|
|
|
|
|
|
ORDER BY 1]); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$sth_functions->execute($schema); |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my %functions; |
130
|
0
|
|
|
|
|
|
while (my ($this_schema,$name,$definition) = $sth_functions->fetchrow_array) { |
131
|
0
|
|
|
|
|
|
$functions{$this_schema.'.'.$name} = $definition; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return \%functions |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=pod |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=encoding UTF-8 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 NAME |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
DBIx::SchemaChecksum::Driver::Pg - Pg driver for DBIx::SchemaChecksum |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 VERSION |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
version 1.102 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 DESCRIPTION |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Get various extra schema info from postgres, if specified via C<driveropts> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=over |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * enum values |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * sequences |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * index definitions |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * triggers |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * functions |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 OPTIONS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 driveropts |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head3 triggers |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
If set to a true value, add info about triggers to the dump. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head3 sequences |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
If set to a true value, add info about sequences to the dump. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head3 functions |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
If set to a true value, add info about functions to the dump. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 AUTHORS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=over 4 |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Thomas Klausner <domm@cpan.org> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Maroš Kollár <maros@cpan.org> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Klaus Ita <koki@worstofall.com> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=back |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Thomas Klausner, Maroš Kollár, Klaus Ita. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
210
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |