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',
14 default_function => 'now()',
17 password => $password,
21 CREATE TABLE pg_loader_test1 (
22 id SERIAL NOT NULL PRIMARY KEY,
27 COMMENT ON TABLE pg_loader_test1 IS 'The Table'
30 COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
33 CREATE TABLE pg_loader_test2 (
34 id SERIAL NOT NULL PRIMARY KEY,
39 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'
41 # Test to make sure data_types that don't need a size => don't
42 # have one and check varying types have the correct size.
44 CREATE TABLE pg_loader_test3 (
45 id SERIAL NOT NULL PRIMARY KEY,
48 a_bigserial BIGSERIAL,
58 a_double_precision DOUBLE PRECISION,
65 an_interval_with_precision INTERVAL(2),
81 a_time_with_precision TIME(2),
82 a_time_without_time_zone TIME WITHOUT TIME ZONE,
83 a_time_without_time_zone_with_precision TIME(2) WITHOUT TIME ZONE,
84 a_time_with_time_zone TIME WITH TIME ZONE,
85 a_time_with_time_zone_with_precision TIME(2) WITH TIME ZONE,
86 a_timestamp TIMESTAMP,
87 a_timestamp_with_precision TIMESTAMP(2),
88 a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
89 a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
90 a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
91 a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE,
92 a_bit_varying_with_precision BIT VARYING(2),
93 a_varbit_with_precision VARBIT(2),
94 a_character_varying_with_precision CHARACTER VARYING(2),
95 a_varchar_with_precision VARCHAR(2),
96 a_character_with_precision CHARACTER(2),
97 a_char_with_precision CHAR(2),
98 the_numeric NUMERIC(6, 3),
99 the_decimal DECIMAL(6, 3)
103 drop => [ qw/ pg_loader_test1 pg_loader_test2 pg_loader_test3 / ],
106 my ($schema, $monikers, $classes) = @_;
108 my $class = $classes->{pg_loader_test1};
109 my $filename = $schema->_loader->_get_dump_filename($class);
112 local ($/, @ARGV) = (undef, $filename);
116 like $code, qr/^=head1 NAME\n\n^$class - The Table\n\n^=cut\n/m,
119 like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
120 'column comment and attrs';
122 $class = $classes->{pg_loader_test2};
123 $filename = $schema->_loader->_get_dump_filename($class);
126 local ($/, @ARGV) = (undef, $filename);
130 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,
131 'long table comment is in DESCRIPTION';
133 my $rsrc = $schema->resultset($monikers->{pg_loader_test3})
135 my @type_columns = grep /^a/, $rsrc->columns;
136 my @without_precision = grep !/_with_precision\z/, @type_columns;
137 my @with_precision = grep /_with_precision\z/, @type_columns;
140 apply { s/_with_precision\z// } @with_precision
143 for my $col (@without_precision) {
144 my ($data_type) = $col =~ /^an?_(.*)/;
145 ($data_type = uc $data_type) =~ s/_/ /g;
147 ok((not exists $rsrc->column_info($col)->{size}),
149 (exists $with_precision{$col} ? 'without precision ' : '') .
150 "has no 'size' column_info")
151 or diag "size is ".$rsrc->column_info($col)->{size}."\n";
154 for my $col (@with_precision) {
155 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
156 ($data_type = uc $data_type) =~ s/_/ /g;
157 my $size = $rsrc->column_info($col)->{size};
160 "$data_type with precision has a correct 'size' column_info";
163 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
164 'size for NUMERIC(precision, scale) is correct';
166 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
167 'size for DECIMAL(precision, scale) is correct';
172 if( !$dsn || !$user ) {
173 $tester->skip_tests('You need to set the DBICTEST_PG_DSN, _USER, and _PASS environment variables');
176 $tester->run_tests();