| 1 | package SQL::Translator::Producer::PostgreSQL; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | SQL::Translator::Producer::PostgreSQL - PostgreSQL producer for SQL::Translator | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | my $t = SQL::Translator->new( parser => '...', producer => 'PostgreSQL' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | $t->translate; | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Creates a DDL suitable for PostgreSQL. Very heavily based on the Oracle | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | producer. | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | Now handles PostGIS Geometry and Geography data types on table definitions. | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Does not yet support PostGIS Views. | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head2 Producer Args | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | You can change the global behavior of the producer by passing the following options to the | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | C<producer_args> attribute of C<SQL::Translator>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =item postgres_version | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | The version of postgres to generate DDL for. Turns on features only available in later versions. The following features are supported | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =item IF EXISTS | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | If your postgres_version is higher than 8.003 (I should hope it is by now), then the DDL | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | generated for dropping objects in the database will contain IF EXISTS. | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =item attach_comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Generates table and column comments via the COMMENT command rather than as a comment in | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | the DDL. You could then look it up with \dt+ or \d+ (for tables and columns respectively) | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | in psql. The comment is dollar quoted with $comment$ so you can include ' in it. Just to clarify: you get this | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | CREATE TABLE foo ...; | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | COMMENT on TABLE foo IS $comment$hi there$comment$; | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | instead of this | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | -- comment | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | CREAT TABLE foo ...; | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | =head2 Extra args | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | Various schema types support various options via the C<extra> attribute. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =item Tables | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =item temporary | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Produces a temporary table. | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =item Views | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =item temporary | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Produces a temporary view. | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =item materialized | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Produces a materialized view. | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =item Fields | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | =item list, custom_type_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | For enum types, list is the list of valid values, and custom_type_name is the name that | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | the type should have. Defaults to $table_$field_type. | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =item geometry_type, srid, dimensions, geography_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | Fields for use with PostGIS types. | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | our ( $DEBUG, $WARN ); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | our $VERSION = '1.6_3'; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ▶ | $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | use base qw(SQL::Translator::Producer); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | ▶ | use SQL::Translator::Schema::Constants; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | use SQL::Translator::Utils qw(debug header_comment parse_dbms_version batch_alter_table_statements normalize_quote_options); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | ▶ | use SQL::Translator::Generator::DDL::PostgreSQL; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | use constant MAX_ID_LENGTH => 62; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | my ($quoting_generator, $nonquoting_generator); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | sub _generator { | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 316 | ▶ | my $options = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generator: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 316 | ▶ | return $options->{generator} if exists $options->{generator}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 157 | ▶ | return normalize_quote_options($options) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
normalize_quote_options($options) ? $quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new : $nonquoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new("quote_chars", [])
$quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new
MC/DC0%0/2
normalize_quote_options($options) ? $quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new : $nonquoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new("quote_chars", [])
normalize_quote_options($options) ? $quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new : $nonquoting_generator
"SQL::Translator::Generator::DDL::PostgreSQL"->new("quote_chars", [])
MC/DC0%0/2
$quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new
$quoting_generator
"SQL::Translator::Generator::DDL::PostgreSQL"->new
Truth table66%2/3
A ||= B
A= normalize_quote_options($options) ? $quoting_generator ||= "SQL::Translator::Generator::DDL::PostgreSQL"->new : $nonquoting_generatorB= "SQL::Translator::Generator::DDL::PostgreSQL"->new("quote_chars", [])
Truth table66%2/3
A ||= B
A= $quoting_generatorB= "SQL::Translator::Generator::DDL::PostgreSQL"->new
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ? $quoting_generator ||= SQL::Translator::Generator::DDL::PostgreSQL->new | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | : $nonquoting_generator ||= SQL::Translator::Generator::DDL::PostgreSQL->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | quote_chars => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | my ( %translate ); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | %translate = ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # MySQL types | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | double => 'double precision', | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | decimal => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | int => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | mediumint => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | tinyint => 'smallint', | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | char => 'character', | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | varchar => 'character varying', | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | longtext => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | mediumtext => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | tinytext => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | tinyblob => 'bytea', | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | blob => 'bytea', | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | mediumblob => 'bytea', | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | longblob => 'bytea', | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | enum => 'character varying', | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | set => 'character varying', | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | datetime => 'timestamp', | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | year => 'date', | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Oracle types | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | number => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | varchar2 => 'character varying', | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | long => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | clob => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Sybase types | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | comment => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # MS Access types | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | memo => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | my %truncated; | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | =head1 PostgreSQL Create Table Syntax | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | { column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | | table_constraint } [, ... ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | [ INHERITS ( parent_table [, ... ] ) ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | [ WITH OIDS | WITHOUT OIDS ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | where column_constraint is: | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | [ CONSTRAINT constraint_name ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | { NOT NULL | NULL | UNIQUE | PRIMARY KEY | | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | CHECK (expression) | | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | [ ON DELETE action ] [ ON UPDATE action ] } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | and table_constraint is: | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | [ CONSTRAINT constraint_name ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | { UNIQUE ( column_name [, ... ] ) | | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | PRIMARY KEY ( column_name [, ... ] ) | | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | CHECK ( expression ) | | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ] } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | =head1 Create Index Syntax | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | CREATE [ UNIQUE ] INDEX index_name ON table | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | [ USING acc_method ] ( column [ ops_name ] [, ...] ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | [ INCLUDE ( column [, ...] ) ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | [ WHERE predicate ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | CREATE [ UNIQUE ] INDEX index_name ON table | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | [ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | [ WHERE predicate ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | sub produce { | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | my $translator = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
produce: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | local $DEBUG = $translator->debug; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | local $WARN = $translator->show_warnings; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | my $no_comments = $translator->no_comments; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | my $add_drop_table = $translator->add_drop_table; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | my $schema = $translator->schema; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | my $pargs = $translator->producer_args; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | my $postgres_version = parse_dbms_version( | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | $pargs->{postgres_version}, 'perl' | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | my $generator = _generator({ quote_identifiers => $translator->quote_identifiers }); | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | my @output; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | push @output, header_comment unless ($no_comments); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | my (@table_defs, @fks); | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | my %type_defs; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 8 | for my $table ( $schema->get_tables ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | my ($table_def, $fks) = create_table($table, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | no_comments => $no_comments, | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | postgres_version => $postgres_version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | add_drop_table => $add_drop_table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | type_defs => \%type_defs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | attach_comments => $pargs->{attach_comments} | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 22 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 22 | push @table_defs, $table_def; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 22 | push @fks, @$fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 8 | for my $view ( $schema->get_views ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | push @table_defs, create_view($view, { | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | postgres_version => $postgres_version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | add_drop_view => $add_drop_table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | no_comments => $no_comments, | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | for my $trigger ( $schema->get_triggers ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 14 | push @table_defs, create_trigger( $trigger, { | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | add_drop_trigger => $add_drop_table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | no_comments => $no_comments, | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 8 | push @output, map { "$_;\n\n" } values %type_defs; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 8 | push @output, map { "$_;\n\n" } @table_defs; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 8 | ▶ | if ( @fks ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 5 | ▶ | push @output, "--\n-- Foreign Key Definitions\n--\n\n" unless $no_comments; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | push @output, map { "$_;\n\n" } @fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 8 | ▶ | if ( $WARN ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if ( %truncated ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | warn "Truncated " . keys( %truncated ) . " names:\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | warn "\t" . join( "\n\t", sort keys %truncated ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | ? @output | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | ▶ | : join ('', @output); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 6 | my %global_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub mk_name { | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | my $basename = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mk_name: not called CC=16 SCAR=56.1
Pod
undocumented
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | my $type = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | my $scope = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | my $critical = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $basename_orig = $basename; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | my $max_name = $type | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ? MAX_ID_LENGTH - (length($type) + 1) | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | : MAX_ID_LENGTH; | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $basename = substr( $basename, 0, $max_name ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | if length( $basename ) > $max_name; | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | my $name = $type ? "${type}_$basename" : $basename; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ( $basename ne $basename_orig and $critical ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$basename ne $basename_orig and $critical
MC/DC0%0/2
$basename ne $basename_orig and $critical
$basename ne $basename_orig
$critical
Truth table0%0/3
A and B
A= $basename ne $basename_origB= $critical
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | my $show_type = $type ? "+'$type'" : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | warn "Truncating '$basename_orig'$show_type to ", MAX_ID_LENGTH, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | " character limit to make '$name'\n" if $WARN; | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $truncated{ $basename_orig } = $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $scope ||= \%global_names; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$scope ||= \%global_names
MC/DC0%0/1
$scope ||= \%global_names
$scope
Truth table0%0/2
A
A= $scope
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if ( my $prev = $scope->{ $name } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $name_orig = $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $name .= sprintf( "%02d", ++$prev ); | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | substr($name, MAX_ID_LENGTH - 3) = "00" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | if length( $name ) > MAX_ID_LENGTH; | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | warn "The name '$name_orig' has been changed to ", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | "'$name' to make it unique.\n" if $WARN; | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $scope->{ $name_orig }++; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $scope->{ $name }++; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 6 | sub is_geometry { | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | 234 | ▶ | my $field = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_geometry: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 234 | ▶ | return 1 if $field->data_type eq 'geometry'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | sub is_geography { | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $field = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_geography: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | return 1 if $field->data_type eq 'geography'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | sub create_table | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 24 | ▶ | my ($table, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_table: called CC=24 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 24 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 24 | ▶ | my $no_comments = $options->{no_comments} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'no_comments'} || 0
MC/DC100%1/1
$options->{'no_comments'} || 0
$options->{'no_comments'}
Truth table100%2/2
A
A= $options->{'no_comments'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 24 | ▶ | my $add_drop_table = $options->{add_drop_table} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'add_drop_table'} || 0
MC/DC100%1/1
$options->{'add_drop_table'} || 0
$options->{'add_drop_table'}
Truth table100%2/2
A
A= $options->{'add_drop_table'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 24 | ▶ | my $postgres_version = $options->{postgres_version} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options->{'postgres_version'} || 0
MC/DC0%0/1
$options->{'postgres_version'} || 0
$options->{'postgres_version'}
Truth table50%1/2
A
A= $options->{'postgres_version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 24 | ▶ | my $type_defs = $options->{type_defs} || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'type_defs'} || {}
MC/DC100%1/1
$options->{'type_defs'} || {}
$options->{'type_defs'}
Truth table100%2/2
A
A= $options->{'type_defs'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 24 | my $attach_comments = $options->{attach_comments}; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 24 | ▶ | my $table_name = $table->name or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 24 | my $table_name_qt = $generator->quote($table_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 24 | my ( @comments, @field_defs, @index_defs, @constraint_defs, @fks ); | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 24 | ▶ | push @comments, "--\n-- Table: $table_name\n--\n" unless $no_comments; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 24 | my @comment_statements; | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | 24 | ▶ | if ( my $comments = $table->comments ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | if ( $attach_comments) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # this follows the example in the MySQL producer, where all comments are added as | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # table comments, even though they could have originally been parsed as DDL comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # quoted via $$ string so there can be 'quotes' inside the comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | my $comment_ddl = "COMMENT on TABLE $table_name_qt IS \$comment\$$comments\$comment\$"; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | push @comment_statements, $comment_ddl; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | } elsif (!$no_comments) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $comments =~ s/^/-- /mg; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | push @comments, "-- Comments:\n$comments\n--\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Fields | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 24 | for my $field ( $table->get_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 74 | push @field_defs, create_field($field, { | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | postgres_version => $postgres_version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | type_defs => $type_defs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | constraint_defs => \@constraint_defs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | attach_comments => $attach_comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 74 | ▶ | if ( $attach_comments ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | my $field_comments = $field->comments; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | ▶ | next unless $field_comments; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | my $field_name_qt = $generator->quote($field->name); | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | 2 | my $comment_ddl = | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | "COMMENT on COLUMN $table_name_qt.$field_name_qt IS \$comment\$$field_comments\$comment\$"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | push @comment_statements, $comment_ddl; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Index Declarations | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 24 | for my $index ( $table->get_indices ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 5 | my ($idef, $constraints) = create_index($index, { | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | postgres_version => $postgres_version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 5 | ▶ | $idef and push @index_defs, $idef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 5 | push @constraint_defs, @$constraints; | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # Table constraints | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 24 | for my $c ( $table->get_constraints ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | 35 | my ($cdefs, $fks) = create_constraint($c, { | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | generator => $generator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 35 | push @constraint_defs, @$cdefs; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 35 | push @fks, @$fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 24 | my $create_statement = join("\n", @comments); | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 24 | ▶ | if ($add_drop_table) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 20 | ▶ | if ($postgres_version >= 8.002) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $create_statement .= "DROP TABLE IF EXISTS $table_name_qt CASCADE;\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 20 | $create_statement .= "DROP TABLE $table_name_qt CASCADE;\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 24 | ▶ | my $temporary = $table->extra->{temporary} ? "TEMPORARY " : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | $create_statement .= "CREATE ${temporary}TABLE $table_name_qt (\n" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 24 | join( ",\n", map { " $_" } @field_defs, @constraint_defs ). | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | "\n)" | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 24 | ▶ | $create_statement .= @index_defs ? ';' : q{}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 24 | ▶ | $create_statement .= ( $create_statement =~ /;$/ ? "\n" : q{} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | . join(";\n", @index_defs); | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # Geometry | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 24 | ▶ | if (my @geometry_columns = grep { is_geometry($_) } $table->get_fields) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | ▶ | $create_statement .= join(";\n", '', map{ drop_geometry_column($_, $options) } @geometry_columns) if $options->{add_drop_table}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | $create_statement .= join(";\n", '', map{ add_geometry_column($_, $options) } @geometry_columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 24 | ▶ | if (@comment_statements) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 2 | $create_statement .= join(";\n", '', @comment_statements); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 24 | return $create_statement, \@fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | sub create_view { | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 10 | ▶ | my ($view, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_view: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 10 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | 10 | ▶ | my $postgres_version = $options->{postgres_version} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'postgres_version'} || 0
MC/DC100%1/1
$options->{'postgres_version'} || 0
$options->{'postgres_version'}
Truth table100%2/2
A
A= $options->{'postgres_version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 10 | my $add_drop_view = $options->{add_drop_view}; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 10 | my $view_name = $view->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 10 | debug("PKG: Looking at view '${view_name}'\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 10 | my $create = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | $create .= "--\n-- View: " . $generator->quote($view_name) . "\n--\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 10 | ▶ | unless $options->{no_comments}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 10 | ▶ | if ($add_drop_view) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 7 | ▶ | if ($postgres_version >= 8.002) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | $create .= "DROP VIEW IF EXISTS " . $generator->quote($view_name) . ";\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 6 | $create .= "DROP VIEW " . $generator->quote($view_name) . ";\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 10 | $create .= 'CREATE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 10 | my $extra = $view->extra; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | 10 | ▶ | $create .= " TEMPORARY" if exists($extra->{temporary}) && $extra->{temporary}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $extra->{"temporary"} and $extra->{"temporary"}
MC/DC50%1/2
exists $extra->{"temporary"} and $extra->{"temporary"}
exists $extra->{"temporary"}
$extra->{"temporary"}
Truth table66%2/3
A and B
A= exists $extra->{"temporary"}B= $extra->{"temporary"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | ▶ | $create .= " MATERIALIZED" if exists($extra->{materialized}) && $extra->{materialized}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $extra->{"materialized"} and $extra->{"materialized"}
MC/DC50%1/2
exists $extra->{"materialized"} and $extra->{"materialized"}
exists $extra->{"materialized"}
$extra->{"materialized"}
Truth table66%2/3
A and B
A= exists $extra->{"materialized"}B= $extra->{"materialized"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 10 | $create .= " VIEW " . $generator->quote($view_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 10 | ▶ | if ( my @fields = $view->fields ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 9 | my $field_list = join ', ', map { $generator->quote($_) } @fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 9 | $create .= " ( ${field_list} )"; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 10 | ▶ | if ( my $sql = $view->sql ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 10 | $create .= " AS\n ${sql}\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 10 | ▶ | if ( $extra->{check_option} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | $create .= ' WITH ' . uc $extra->{check_option} . ' CHECK OPTION'; | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 10 | return $create; | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 6 | my %field_name_scope; | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | sub create_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 102 | ▶ | my ($field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_field: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 102 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 102 | my $table_name = $field->table->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 102 | ▶ | my $constraint_defs = $options->{constraint_defs} || []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'constraint_defs'} || []
MC/DC100%1/1
$options->{'constraint_defs'} || []
$options->{'constraint_defs'}
Truth table100%2/2
A
A= $options->{'constraint_defs'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 102 | ▶ | my $postgres_version = $options->{postgres_version} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'postgres_version'} || 0
MC/DC100%1/1
$options->{'postgres_version'} || 0
$options->{'postgres_version'}
Truth table100%2/2
A
A= $options->{'postgres_version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 102 | ▶ | my $type_defs = $options->{type_defs} || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'type_defs'} || {}
MC/DC100%1/1
$options->{'type_defs'} || {}
$options->{'type_defs'}
Truth table100%2/2
A
A= $options->{'type_defs'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 102 | my $attach_comments = $options->{attach_comments}; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 102 | ▶ | $field_name_scope{$table_name} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field_name_scope{$table_name} ||= {}
MC/DC100%1/1
$field_name_scope{$table_name} ||= {}
$field_name_scope{$table_name}
Truth table100%2/2
A
A= $field_name_scope{$table_name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 102 | my $field_name = $field->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 102 | my $field_comments = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | 102 | ▶ | if ( !$attach_comments and my $comments = $field->comments ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $attach_comments and my $comments = $field->comments
MC/DC100%2/2
not $attach_comments and my $comments = $field->comments
not $attach_comments
my $comments = $field->comments
Truth table100%3/3
not(A) and B
A= not $attach_commentsB= my $comments = $field->comments
| |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 | $comments =~ s/(?<!\A)^/ -- /mg; | |||||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | $field_comments = "-- $comments\n "; | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 102 | my $field_def = $field_comments . $generator->quote($field_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # Datatype | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 102 | my $data_type = lc $field->data_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | 102 | my %extra = $field->extra; | |||||||||||||||||||||||||||||||||||||||||||||
| 527 | 102 | ▶ | my $list = $extra{'list'} || []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$extra{'list'} || []
MC/DC100%1/1
$extra{'list'} || []
$extra{'list'}
Truth table100%2/2
A
A= $extra{'list'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 102 | my $commalist = join( ', ', map { __PACKAGE__->_quote_string($_) } @$list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 102 | ▶ | if ($postgres_version >= 8.003 && $data_type eq 'enum') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$postgres_version >= "8.003" and $data_type eq "enum"
MC/DC100%2/2
$postgres_version >= "8.003" and $data_type eq "enum"
$postgres_version >= "8.003"
$data_type eq "enum"
Truth table100%3/3
A and B
A= $postgres_version >= "8.003"B= $data_type eq "enum"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 2 | ▶ | my $type_name = $extra{'custom_type_name'} || $field->table->name . '_' . $field->name . '_type'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$extra{'custom_type_name'} || $field->table->name . '_' . $field->name . '_type'
MC/DC100%1/1
$extra{'custom_type_name'} || $field->table->name . '_' . $field->name . '_type'
$extra{'custom_type_name'}
Truth table100%2/2
A
A= $extra{'custom_type_name'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | $field_def .= ' '. $type_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | my $new_type_def = "DROP TYPE IF EXISTS $type_name CASCADE;\n" . | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | "CREATE TYPE $type_name AS ENUM ($commalist)"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | ▶ | if (! exists $type_defs->{$type_name} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | $type_defs->{$type_name} = $new_type_def; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | } elsif ( $type_defs->{$type_name} ne $new_type_def ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | die "Attempted to redefine type name '$type_name' as a different type.\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 100 | $field_def .= ' '. convert_datatype($field); | |||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Default value | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 102 | __PACKAGE__->_apply_default_value( | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | $field, | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | \$field_def, | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 'NULL' => \'NULL', | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 'now()' => 'now()', | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP', | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # Not null constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 102 | ▶ | $field_def .= ' NOT NULL' unless $field->is_nullable; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # Geometry constraints | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 102 | ▶ | if (is_geometry($field)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 3 | foreach ( create_geometry_constraints($field, $options) ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | 9 | my ($cdefs, $fks) = create_constraint($_, $options); | |||||||||||||||||||||||||||||||||||||||||||||
| 568 | 9 | push @$constraint_defs, @$cdefs; | |||||||||||||||||||||||||||||||||||||||||||||
| 569 | 9 | push @$fks, @$fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 102 | return $field_def; | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 6 | sub create_geometry_constraints { | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | 7 | ▶ | my ($field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_geometry_constraints: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 7 | my $fname = _generator($options)->quote($field); | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | 7 | my @constraints; | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | push @constraints, SQL::Translator::Schema::Constraint->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | name => "enforce_dims_".$field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 7 | expression => "(ST_NDims($fname) = ".$field->extra->{dimensions}.")", | |||||||||||||||||||||||||||||||||||||||||||||
| 585 | table => $field->table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | type => CHECK_C, | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | push @constraints, SQL::Translator::Schema::Constraint->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | name => "enforce_srid_".$field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 7 | expression => "(ST_SRID($fname) = ".$field->extra->{srid}.")", | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | table => $field->table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | type => CHECK_C, | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | push @constraints, SQL::Translator::Schema::Constraint->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | name => "enforce_geotype_".$field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 7 | expression => "(GeometryType($fname) = ". __PACKAGE__->_quote_string($field->extra->{geometry_type}) ."::text OR $fname IS NULL)", | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | table => $field->table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | type => CHECK_C, | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 7 | return @constraints; | |||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 6 | my %index_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | sub create_index | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 16 | ▶ | my ($index, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_index: called CC=19 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 16 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 612 | 16 | my $table_name = $index->table->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | 16 | ▶ | my $postgres_version = $options->{postgres_version} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'postgres_version'} || 0
MC/DC100%1/1
$options->{'postgres_version'} || 0
$options->{'postgres_version'}
Truth table100%2/2
A
A= $options->{'postgres_version'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 16 | my ($index_def, @constraint_defs); | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | my $name | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | = $index->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 16 | ▶ | || join('_', $table_name, 'idx', ++$index_name{ $table_name }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$index->name || join('_', $table_name, 'idx', ++$index_name{$table_name})
MC/DC0%0/2
$index->name || join('_', $table_name, 'idx', ++$index_name{$table_name})
$index->name
join('_', $table_name, 'idx', ++$index_name{$table_name})
Truth table33%1/3
A || B
A= $index->nameB= join('_', $table_name, 'idx', ++$index_name{$table_name})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 16 | ▶ | my $type = $index->type || NORMAL; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$index->type || 'NORMAL'
MC/DC0%0/1
$index->type || 'NORMAL'
$index->type
Truth table50%1/2
A
A= $index->type
| |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 16 | my @fields = $index->fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 623 | 16 | ▶ | return unless @fields; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 16 | my %index_extras; | |||||||||||||||||||||||||||||||||||||||||||||
| 626 | 16 | for my $opt ( $index->options ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | 6 | ▶ | if ( ref $opt eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 6 | foreach my $key (keys %$opt) { | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 6 | my $value = $opt->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | 6 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 6 | ▶ | if ( uc($key) eq 'USING' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | $index_extras{using} = "USING $value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | elsif ( uc($key) eq 'WHERE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 2 | $index_extras{where} = "WHERE $value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | elsif ( uc($key) eq 'INCLUDE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 2 | ▶ | next unless $postgres_version >= 11; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | ▶ | die 'Include list must be an arrayref' unless ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | my $value_list = join ', ', @$value; | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | $index_extras{include} = "INCLUDE ($value_list)" | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 16 | my $def_start = 'CONSTRAINT ' . $generator->quote($name) . ' '; | |||||||||||||||||||||||||||||||||||||||||||||
| 648 | 16 | ▶ | my $field_names = '(' . join(", ", (map { $_ =~ /\(.*\)/ ? $_ : ( $generator->quote($_) ) } @fields)) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 16 | ▶ | if ( $type eq PRIMARY_KEY ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | push @constraint_defs, "${def_start}PRIMARY KEY ".$field_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 652 | elsif ( $type eq UNIQUE ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | push @constraint_defs, "${def_start}UNIQUE " .$field_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | elsif ( $type eq NORMAL ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 656 | $index_def = | ||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 'CREATE INDEX ' . $generator->quote($name) . ' on ' . $generator->quote($table_name) . ' ' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 15 | join ' ', grep { defined } $index_extras{using}, $field_names, @index_extras{'include', 'where'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | warn "Unknown index type ($type) on table $table_name.\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | if $WARN; | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 16 | return $index_def, \@constraint_defs; | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||
| 669 | sub create_constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 671 | 69 | ▶ | my ($c, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_constraint: called CC=16 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 69 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | 69 | my $table_name = $c->table->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | 69 | my (@constraint_defs, @fks); | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 69 | ▶ | my $name = $c->name || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c->name || ''
MC/DC100%1/1
$c->name || ''
$c->name
Truth table100%2/2
A
A= $c->name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 69 | my @fields = grep { defined } $c->fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 69 | my @rfields = grep { defined } $c->reference_fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 69 | ▶ | next if !@fields && $c->type ne CHECK_C; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @fields and $c->type ne "CHECK"
MC/DC0%0/2
not @fields and $c->type ne "CHECK"
not @fields
$c->type ne "CHECK"
Truth table66%2/3
not(A) and B
A= not @fieldsB= $c->type ne "CHECK"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 69 | ▶ | my $def_start = $name ? 'CONSTRAINT ' . $generator->quote($name) . ' ' : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 69 | ▶ | my $field_names = '(' . join(", ", (map { $_ =~ /\(.*\)/ ? $_ : ( $generator->quote($_) ) } @fields)) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 69 | ▶ | if ( $c->type eq PRIMARY_KEY ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 17 | push @constraint_defs, "${def_start}PRIMARY KEY ".$field_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | elsif ( $c->type eq UNIQUE ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 16 | push @constraint_defs, "${def_start}UNIQUE " .$field_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | elsif ( $c->type eq CHECK_C ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 18 | my $expression = $c->expression; | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | 18 | push @constraint_defs, "${def_start}CHECK ($expression)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | elsif ( $c->type eq FOREIGN_KEY ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 8 | my $def .= "ALTER TABLE " . $generator->quote($table_name) . " ADD ${def_start}FOREIGN KEY $field_names" | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | . "\n REFERENCES " . $generator->quote($c->reference_table); | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 8 | ▶ | if ( @rfields ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 8 | $def .= ' (' . join( ', ', map { $generator->quote($_) } @rfields ) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 8 | ▶ | if ( $c->match_type ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | $def .= ' MATCH ' . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 706 | ( $c->match_type =~ /full/i ) ? 'FULL' : 'PARTIAL'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 8 | ▶ | if ( $c->on_delete ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $def .= ' ON DELETE '. $c->on_delete; | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 8 | ▶ | if ( $c->on_update ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | $def .= ' ON UPDATE '. $c->on_update; | |||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 8 | ▶ | if ( $c->deferrable ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 8 | $def .= ' DEFERRABLE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 8 | push @fks, "$def"; | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 69 | return \@constraint_defs, \@fks; | |||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||
| 727 | sub create_trigger { | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 14 | ▶ | my ($trigger,$options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_trigger: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 14 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 14 | my @statements; | |||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | push @statements, sprintf( 'DROP TRIGGER IF EXISTS %s', $generator->quote($trigger->name) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 14 | ▶ | if $options->{add_drop_trigger}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 14 | ▶ | my $scope = $trigger->scope || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$trigger->scope || ''
MC/DC100%1/1
$trigger->scope || ''
$trigger->scope
Truth table100%2/2
A
A= $trigger->scope
| |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 14 | ▶ | $scope = " FOR EACH $scope" if $scope; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | push @statements, sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 'CREATE TRIGGER %s %s %s ON %s%s %s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | $generator->quote($trigger->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 742 | $trigger->perform_action_when, | ||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 14 | join( ' OR ', @{ $trigger->database_events } ), | |||||||||||||||||||||||||||||||||||||||||||||
| 744 | $generator->quote($trigger->on_table), | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | $scope, | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | $trigger->action, | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 14 | return @statements; | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | sub convert_datatype | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 140 | ▶ | my ($field) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_datatype: called CC=26 SCAR=32.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 140 | my @size = $field->size; | |||||||||||||||||||||||||||||||||||||||||||||
| 757 | 140 | my $data_type = lc $field->data_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | 140 | my $array = $data_type =~ s/\[\]$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 140 | ▶ | if ( $data_type eq 'enum' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # my $len = 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # $len = ($len < length($_)) ? length($_) : $len for (@$list); | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # my $chk_name = mk_name( $table_name.'_'.$field_name, 'chk' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # push @$constraint_defs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | # 'CONSTRAINT "$chk_name" CHECK (' . $generator->quote(field_name) . | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | # qq[IN ($commalist))]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | $data_type = 'character varying'; | |||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 769 | elsif ( $data_type eq 'set' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $data_type = 'character varying'; | |||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | elsif ( $field->is_auto_increment ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 19 | ▶ | if ( (defined $size[0] && $size[0] > 11) or $data_type eq 'bigint' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $size[0] and $size[0] > 11 or $data_type eq "bigint"
defined $size[0] and $size[0] > 11
MC/DC66%2/3
defined $size[0] and $size[0] > 11 or $data_type eq "bigint"
defined $size[0]
$size[0] > 11
$data_type eq "bigint"
Truth table60%3/5
A and B or C
A= defined $size[0]B= $size[0] > 11C= $data_type eq "bigint"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 2 | $data_type = 'bigserial'; | |||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 17 | $data_type = 'serial'; | |||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 19 | undef @size; | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 782 | $data_type = defined $translate{ lc $data_type } ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 121 | ▶ | $translate{ lc $data_type } : | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | $data_type; | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 140 | ▶ | if ( $data_type =~ /^time/i || $data_type =~ /^interval/i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data_type =~ /^time/i or $data_type =~ /^interval/i
MC/DC100%2/2
$data_type =~ /^time/i or $data_type =~ /^interval/i
$data_type =~ /^time/i
$data_type =~ /^interval/i
Truth table100%3/3
A or B
A= $data_type =~ /^time/iB= $data_type =~ /^interval/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 13 | ▶ | if ( defined $size[0] && $size[0] > 6 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $size[0] and $size[0] > 6
MC/DC50%1/2
defined $size[0] and $size[0] > 6
defined $size[0]
$size[0] > 6
Truth table66%2/3
A and B
A= defined $size[0]B= $size[0] > 6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 1 | $size[0] = 6; | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 140 | ▶ | if ( $data_type eq 'integer' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 17 | ▶ | if ( defined $size[0] && $size[0] > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $size[0] and $size[0] > 0
MC/DC50%1/2
defined $size[0] and $size[0] > 0
defined $size[0]
$size[0] > 0
Truth table66%2/3
A and B
A= defined $size[0]B= $size[0] > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 15 | ▶ | if ( $size[0] > 10 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 10 | $data_type = 'bigint'; | |||||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | elsif ( $size[0] < 5 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $data_type = 'smallint'; | |||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 801 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 5 | $data_type = 'integer'; | |||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 2 | $data_type = 'integer'; | |||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 140 | my $type_with_size = join('|', | |||||||||||||||||||||||||||||||||||||||||||||
| 811 | 'bit', 'varbit', 'character', 'bit varying', 'character varying', | ||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 'time', 'timestamp', 'interval', 'numeric', 'float' | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 140 | ▶ | if ( $data_type !~ /$type_with_size/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 60 | @size = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 140 | ▶ | if (defined $size[0] && $size[0] > 0 && $data_type =~ /^time/i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
defined $size[0] and $size[0] > 0 and $data_type =~ /^time/i
defined $size[0] and $size[0] > 0
MC/DC100%3/3
defined $size[0] and $size[0] > 0 and $data_type =~ /^time/i
defined $size[0]
$size[0] > 0
$data_type =~ /^time/i
Truth table100%4/4
A and B and C
A= defined $size[0]B= $size[0] > 0C= $data_type =~ /^time/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 5 | $data_type =~ s/^(time.*?)( with.*)?$/$1($size[0])/; | |||||||||||||||||||||||||||||||||||||||||||||
| 821 | 5 | ▶ | $data_type .= $2 if(defined $2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 822 | ▶ | } elsif ( defined $size[0] && $size[0] > 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $size[0] and $size[0] > 0
MC/DC100%2/2
defined $size[0] and $size[0] > 0
defined $size[0]
$size[0] > 0
Truth table100%3/3
A and B
A= defined $size[0]B= $size[0] > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 65 | $data_type .= '(' . join( ',', @size ) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 140 | ▶ | if($array) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 826 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 1 | $data_type .= '[]'; | |||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 831 | # Geography | ||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 140 | ▶ | if($data_type eq 'geography'){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 1 | $data_type .= '('.$field->extra->{geography_type}.','. $field->extra->{srid} .')' | |||||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 140 | return $data_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||||||
| 841 | sub alter_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 842 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 20 | ▶ | my ($from_field, $to_field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_field: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 20 | ▶ | die "Can't alter field in another table" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 846 | if($from_field->table->name ne $to_field->table->name); | ||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 20 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 849 | 20 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # drop geometry column and constraints | ||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 20 | ▶ | push @out, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 853 | drop_geometry_column($from_field, $options), | ||||||||||||||||||||||||||||||||||||||||||||||
| 854 | drop_geometry_constraints($from_field, $options), | ||||||||||||||||||||||||||||||||||||||||||||||
| 855 | if is_geometry($from_field); | ||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # it's necessary to start with rename column cause this would affect | ||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # all of the following statements which would be broken if do the | ||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # rename later | ||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # BUT: drop geometry is done before the rename, cause it work's on the | ||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # $from_field directly | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s RENAME COLUMN %s TO %s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 863 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 864 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 865 | $from_field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 866 | $to_field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 868 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 869 | if($from_field->name ne $to_field->name); | ||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s ALTER COLUMN %s SET NOT NULL', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $to_field->is_nullable and $from_field->is_nullable
MC/DC100%2/2
not $to_field->is_nullable and $from_field->is_nullable
not $to_field->is_nullable
$from_field->is_nullable
Truth table100%3/3
not(A) and B
A= not $to_field->is_nullableB= $from_field->is_nullable
| |||||||||||||||||||||||||||||||||||||||||||||||
| 872 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 873 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | $to_field->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 875 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 876 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 877 | if(!$to_field->is_nullable and $from_field->is_nullable); | ||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $from_field->is_nullable and $to_field->is_nullable
MC/DC100%2/2
not $from_field->is_nullable and $to_field->is_nullable
not $from_field->is_nullable
$to_field->is_nullable
Truth table100%3/3
not(A) and B
A= not $from_field->is_nullableB= $to_field->is_nullable
| |||||||||||||||||||||||||||||||||||||||||||||||
| 880 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 882 | $to_field->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | if (!$from_field->is_nullable and $to_field->is_nullable); | ||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 20 | my $from_dt = convert_datatype($from_field); | |||||||||||||||||||||||||||||||||||||||||||||
| 889 | 20 | my $to_dt = convert_datatype($to_field); | |||||||||||||||||||||||||||||||||||||||||||||
| 890 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s ALTER COLUMN %s TYPE %s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 891 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 892 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 893 | $to_field->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 894 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 895 | $to_dt, | ||||||||||||||||||||||||||||||||||||||||||||||
| 896 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 897 | if($to_dt ne $from_dt); | ||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 20 | my $old_default = $from_field->default_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 900 | 20 | my $new_default = $to_field->default_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 901 | 20 | my $default_value = $to_field->default_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||
| 903 | # fixes bug where output like this was created: | ||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # ALTER TABLE users ALTER COLUMN column SET DEFAULT ThisIsUnescaped; | ||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 20 | ▶ | if(ref $default_value eq "SCALAR" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 1 | $default_value = $$default_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 907 | ▶ | } elsif( defined $default_value && $to_dt =~ /^(character|text|timestamp|date)/xsmi ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $default_value and $to_dt =~ /^(character|text|timestamp|date)/imsx
MC/DC100%2/2
defined $default_value and $to_dt =~ /^(character|text|timestamp|date)/imsx
defined $default_value
$to_dt =~ /^(character|text|timestamp|date)/imsx
Truth table100%3/3
A and B
A= defined $default_valueB= $to_dt =~ /^(character|text|timestamp|date)/imsx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 3 | $default_value = __PACKAGE__->_quote_string($default_value); | |||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $new_default and !defined($old_default) || $old_default ne $new_default
not defined $old_default or $old_default ne $new_default
MC/DC66%2/3
defined $new_default and !defined($old_default) || $old_default ne $new_default
defined $new_default
not defined $old_default
$old_default ne $new_default
Truth table75%3/4
A and not(B) or C
A= defined $new_defaultB= not defined $old_defaultC= $old_default ne $new_default
| |||||||||||||||||||||||||||||||||||||||||||||||
| 912 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 913 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 914 | $to_field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | $default_value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 917 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 918 | if ( defined $new_default && | ||||||||||||||||||||||||||||||||||||||||||||||
| 919 | (!defined $old_default || $old_default ne $new_default) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||
| 921 | # fixes bug where removing the DEFAULT statement of a column | ||||||||||||||||||||||||||||||||||||||||||||||
| 922 | # would result in no change | ||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 20 | ▶ | push @out, sprintf('ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $new_default and defined $old_default
MC/DC100%2/2
not defined $new_default and defined $old_default
not defined $new_default
defined $old_default
Truth table100%3/3
not(A) and B
A= not defined $new_defaultB= defined $old_default
| |||||||||||||||||||||||||||||||||||||||||||||||
| 925 | map($generator->quote($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 926 | $to_field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 927 | $to_field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 928 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 929 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 930 | if ( !defined $new_default && defined $old_default ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # add geometry column and constraints | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 20 | ▶ | push @out, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 934 | add_geometry_column($to_field, $options), | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | add_geometry_constraints($to_field, $options), | ||||||||||||||||||||||||||||||||||||||||||||||
| 936 | if is_geometry($to_field); | ||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 20 | ▶ | return wantarray ? @out : join(";\n", @out); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 2 | ▶ | sub rename_field { alter_field(@_) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||
| 943 | sub add_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 944 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 6 | ▶ | my ($new_field,$options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_field: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 6 | my $out = sprintf('ALTER TABLE %s ADD COLUMN %s', | |||||||||||||||||||||||||||||||||||||||||||||
| 948 | _generator($options)->quote($new_field->table->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 949 | create_field($new_field, $options)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 6 | ▶ | $out .= ";\n".add_geometry_column($new_field, $options) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 951 | . ";\n".add_geometry_constraints($new_field, $options) | ||||||||||||||||||||||||||||||||||||||||||||||
| 952 | if is_geometry($new_field); | ||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 6 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||
| 957 | sub drop_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 4 | ▶ | my ($old_field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_field: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 4 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 4 | my $out = sprintf('ALTER TABLE %s DROP COLUMN %s', | |||||||||||||||||||||||||||||||||||||||||||||
| 964 | $generator->quote($old_field->table->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | $generator->quote($old_field->name)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 4 | ▶ | $out .= ";\n".drop_geometry_column($old_field, $options) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 967 | if is_geometry($old_field); | ||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 4 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||
| 971 | sub add_geometry_column { | ||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 5 | ▶ | my ($field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_geometry_column: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||
| 974 | return sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 975 | "INSERT INTO geometry_columns VALUES (%s,%s,%s,%s,%s,%s,%s)", | ||||||||||||||||||||||||||||||||||||||||||||||
| 976 | map(__PACKAGE__->_quote_string($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 977 | '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 978 | $field->table->schema->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 979 | $options->{table} ? $options->{table} : $field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 980 | $field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 981 | $field->extra->{dimensions}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 982 | $field->extra->{srid}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 983 | $field->extra->{geometry_type}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 5 | ▶ | ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 985 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 986 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||
| 988 | sub drop_geometry_column { | ||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 4 | ▶ | my ($field) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_geometry_column: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 4 | return sprintf( | |||||||||||||||||||||||||||||||||||||||||||||
| 992 | "DELETE FROM geometry_columns WHERE f_table_schema = %s AND f_table_name = %s AND f_geometry_column = %s", | ||||||||||||||||||||||||||||||||||||||||||||||
| 993 | map(__PACKAGE__->_quote_string($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 994 | $field->table->schema->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 995 | $field->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 996 | $field->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 997 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 998 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | sub add_geometry_constraints { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 3 | ▶ | my ($field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_geometry_constraints: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 3 | return join(";\n", map { alter_create_constraint($_, $options) } | |||||||||||||||||||||||||||||||||||||||||||||
| 1005 | create_geometry_constraints($field, $options)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | sub drop_geometry_constraints { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 1 | ▶ | my ($field, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_geometry_constraints: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 1 | return join(";\n", map { alter_drop_constraint($_, $options) } | |||||||||||||||||||||||||||||||||||||||||||||
| 1012 | create_geometry_constraints($field, $options)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | sub alter_table { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 3 | ▶ | my ($to_table, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_table: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 3 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1019 | my $out = sprintf('ALTER TABLE %s %s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | $generator->quote($to_table->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 3 | $options->{alter_table_action}); | |||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 3 | ▶ | $out .= ";\n".$options->{geometry_changes} if $options->{geometry_changes}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 3 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | sub rename_table { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 3 | ▶ | my ($old_table, $new_table, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_table: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 3 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 3 | $options->{alter_table_action} = "RENAME TO " . $generator->quote($new_table); | |||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | my @geometry_changes = map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | drop_geometry_column($_, $options), | ||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 1 | add_geometry_column($_, { %{$options}, table => $new_table }), | |||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 3 | } grep { is_geometry($_) } $old_table->get_fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 3 | ▶ | $options->{geometry_changes} = join (";\n",@geometry_changes) if @geometry_changes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 3 | return alter_table($old_table, $options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | sub alter_create_index { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 1 | ▶ | my ($index, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_create_index: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 1 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 1 | my ($idef, $constraints) = create_index($index, $options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 1 | ▶ | return $index->type eq NORMAL ? $idef | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | : sprintf('ALTER TABLE %s ADD %s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | $generator->quote($index->table->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | join(q{}, @$constraints) | ||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | sub alter_drop_index { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1 | ▶ | my ($index, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_drop_index: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 1 | return 'DROP INDEX '. _generator($options)->quote($index->name); | |||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | sub alter_drop_constraint { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 11 | ▶ | my ($c, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_drop_constraint: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 11 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | # attention: Postgres has a very special naming structure for naming | ||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | # foreign keys and primary keys. It names them using the name of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | # table as prefix and fkey or pkey as suffix, concatenated by an underscore | ||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 11 | my $c_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 11 | ▶ | if( $c->name ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | # Already has a name, just use it | ||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 9 | $c_name = $c->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } elsif ( $c->type eq FOREIGN_KEY ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | # Doesn't have a name, and is foreign key, append '_fkey' | ||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 1 | $c_name = $c->table->name . '_' . ($c->fields)[0] . '_fkey'; | |||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } elsif ( $c->type eq PRIMARY_KEY ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # Doesn't have a name, and is primary key, append '_pkey' | ||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 1 | $c_name = $c->table->name . '_pkey'; | |||||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | return sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 'ALTER TABLE %s DROP CONSTRAINT %s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 11 | map { $generator->quote($_) } $c->table->name, $c_name, | |||||||||||||||||||||||||||||||||||||||||||||
| 1079 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | sub alter_create_constraint { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 14 | ▶ | my ($index, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_create_constraint: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 14 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 14 | my ($defs, $fks) = create_constraint(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | # return if there are no constraint definitions so we don't run | ||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | # into output like this: | ||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | # ALTER TABLE users ADD ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 14 | ▶ | return unless(@{$defs} || @{$fks}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$defs;} or @{$fks;}
MC/DC0%0/2
@{$defs;} or @{$fks;}
@{$defs;}
@{$fks;}
Truth table66%2/3
A or B
A= @{$defs;}B= @{$fks;}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1 | return $index->type eq FOREIGN_KEY ? join(q{}, @{$fks}) | |||||||||||||||||||||||||||||||||||||||||||||
| 1093 | : join( ' ', 'ALTER TABLE', $generator->quote($index->table->name), | ||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 14 | ▶ | 'ADD', join(q{}, @{$defs}, @{$fks}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | sub drop_table { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 3 | ▶ | my ($table, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_table: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 3 | my $generator = _generator($options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 3 | my $out = "DROP TABLE " . $generator->quote($table) . " CASCADE"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 3 | my @geometry_drops = map { drop_geometry_column($_); } grep { is_geometry($_) } $table->get_fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 3 | ▶ | $out .= join(";\n", '', @geometry_drops) if @geometry_drops; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 3 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | sub batch_alter_table { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 12 | ▶ | my ( $table, $diff_hash, $options ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
batch_alter_table: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | # as long as we're not renaming the table we don't need to be here | ||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 12 | ▶ | if ( @{$diff_hash->{rename_table}} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 10 | return batch_alter_table_statements($diff_hash, $options); | |||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | # first we need to perform drops which are on old table | ||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 2 | my @sql = batch_alter_table_statements($diff_hash, $options, qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 1119 | alter_drop_constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | alter_drop_index | ||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | drop_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | )); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | # next comes the rename_table | ||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 2 | my $old_table = $diff_hash->{rename_table}[0][0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 2 | push @sql, rename_table( $old_table, $table, $options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | # for alter_field (and so also rename_field) we need to make sure old | ||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | # field has table name set to new table otherwise calling alter_field dies | ||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | $diff_hash->{alter_field} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 2 | ▶ | [map { $_->[0]->table($table) && $_ } @{$diff_hash->{alter_field}}]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | $diff_hash->{rename_field} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 2 | ▶ | [map { $_->[0]->table($table) && $_ } @{$diff_hash->{rename_field}}]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | # now add everything else | ||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 2 | push @sql, batch_alter_table_statements($diff_hash, $options, qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 1137 | add_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | alter_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | rename_field | ||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | alter_create_index | ||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | alter_create_constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | alter_table | ||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | )); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 2 | return @sql; | |||||||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | # Life is full of misery, loneliness, and suffering -- | ||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | # and it's all over much too soon. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | # Woody Allen | ||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | SQL::Translator, SQL::Translator::Producer::Oracle. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||