3 use dbixcsl_common_tests;
5 use List::MoreUtils 'apply';
7 my $dsn = $ENV{DBICTEST_PG_DSN} || '';
8 my $user = $ENV{DBICTEST_PG_USER} || '';
9 my $password = $ENV{DBICTEST_PG_PASS} || '';
11 my $tester = dbixcsl_common_tests->new(
13 auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY',
16 password => $password,
20 CREATE TABLE pg_loader_test1 (
21 id SERIAL NOT NULL PRIMARY KEY,
26 COMMENT ON TABLE pg_loader_test1 IS 'The Table'
29 COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
32 CREATE TABLE pg_loader_test2 (
33 id SERIAL NOT NULL PRIMARY KEY,
38 COMMENT ON TABLE pg_loader_test2 IS 'very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long comment'
40 # Test to make sure data_types that don't need a size => don't
41 # have one and check varying types have the correct size.
43 CREATE TABLE pg_loader_test3 (
44 id SERIAL NOT NULL PRIMARY KEY,
47 a_bigserial BIGSERIAL,
57 a_double_precision DOUBLE PRECISION,
64 an_interval_with_precision INTERVAL(2),
80 a_time_with_precision TIME(2),
81 a_time_without_time_zone TIME WITHOUT TIME ZONE,
82 a_time_without_time_zone_with_precision TIME(2) WITHOUT TIME ZONE,
83 a_time_with_time_zone TIME WITH TIME ZONE,
84 a_time_with_time_zone_with_precision TIME(2) WITH TIME ZONE,
85 a_timestamp TIMESTAMP,
86 a_timestamp_with_precision TIMESTAMP(2),
87 a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
88 a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
89 a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
90 a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE,
91 a_bit_varying_with_precision BIT VARYING(2),
92 a_varbit_with_precision VARBIT(2),
93 a_character_varying_with_precision CHARACTER VARYING(2),
94 a_varchar_with_precision VARCHAR(2),
95 a_character_with_precision CHARACTER(2),
96 a_char_with_precision CHAR(2),
97 the_numeric NUMERIC(6, 3),
98 the_decimal DECIMAL(6, 3)
102 drop => [ qw/ pg_loader_test1 pg_loader_test2 pg_loader_test3 / ],
105 my ($schema, $monikers, $classes) = @_;
107 my $class = $classes->{pg_loader_test1};
108 my $filename = $schema->_loader->_get_dump_filename($class);
111 local ($/, @ARGV) = (undef, $filename);
115 like $code, qr/^=head1 NAME\n\n^$class - The Table\n\n^=cut\n/m,
118 like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
119 'column comment and attrs';
121 $class = $classes->{pg_loader_test2};
122 $filename = $schema->_loader->_get_dump_filename($class);
125 local ($/, @ARGV) = (undef, $filename);
129 like $code, qr/^=head1 NAME\n\n^$class\n\n=head1 DESCRIPTION\n\n^very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long comment\n\n^=cut\n/m,
130 'long table comment is in DESCRIPTION';
132 my $rsrc = $schema->resultset($monikers->{pg_loader_test3})
134 my @type_columns = grep /^a/, $rsrc->columns;
135 my @without_precision = grep !/_with_precision\z/, @type_columns;
136 my @with_precision = grep /_with_precision\z/, @type_columns;
139 apply { s/_with_precision\z// } @with_precision
142 for my $col (@without_precision) {
143 my ($data_type) = $col =~ /^an?_(.*)/;
144 ($data_type = uc $data_type) =~ s/_/ /g;
146 ok((not exists $rsrc->column_info($col)->{size}),
148 (exists $with_precision{$col} ? 'without precision ' : '') .
149 "has no 'size' column_info")
150 or diag "size is ".$rsrc->column_info($col)->{size}."\n";
153 for my $col (@with_precision) {
154 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
155 ($data_type = uc $data_type) =~ s/_/ /g;
156 my $size = $rsrc->column_info($col)->{size};
159 "$data_type with precision has a correct 'size' column_info";
162 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
163 'size for NUMERIC(precision, scale) is correct';
165 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
166 'size for DECIMAL(precision, scale) is correct';
171 if( !$dsn || !$user ) {
172 $tester->skip_tests('You need to set the DBICTEST_PG_DSN, _USER, and _PASS environment variables');
175 $tester->run_tests();