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'
31 # Test to make sure data_types that don't need a size => don't
32 # have one and check varying types have the correct size.
34 CREATE TABLE pg_loader_test2 (
35 id SERIAL NOT NULL PRIMARY KEY,
38 a_bigserial BIGSERIAL,
48 a_double_precision DOUBLE PRECISION,
55 an_interval_with_precision INTERVAL(2),
71 a_time_with_precision TIME(2),
72 a_time_without_time_zone TIME WITHOUT TIME ZONE,
73 a_time_without_time_zone_with_precision TIME(2) WITHOUT TIME ZONE,
74 a_time_with_time_zone TIME WITH TIME ZONE,
75 a_time_with_time_zone_with_precision TIME(2) WITH TIME ZONE,
76 a_timestamp TIMESTAMP,
77 a_timestamp_with_precision TIMESTAMP(2),
78 a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
79 a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
80 a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
81 a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE,
82 a_bit_varying_with_precision BIT VARYING(2),
83 a_varbit_with_precision VARBIT(2),
84 a_character_varying_with_precision CHARACTER VARYING(2),
85 a_varchar_with_precision VARCHAR(2),
86 a_character_with_precision CHARACTER(2),
87 a_char_with_precision CHAR(2),
88 the_numeric NUMERIC(6, 3),
89 the_decimal DECIMAL(6, 3)
92 # XXX figure out what to do with DECIMAL(precision, scale) aka
93 # NUMERIC(precision, scale)
95 drop => [ qw/ pg_loader_test1 pg_loader_test2 / ],
98 my ($schema, $monikers, $classes) = @_;
100 my $class = $classes->{pg_loader_test1};
101 my $filename = $schema->_loader->_get_dump_filename($class);
104 local ($/, @ARGV) = (undef, $filename);
108 like $code, qr/^=head1 NAME\n\n^$class - The Table\n\n^=cut\n/m,
111 like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
112 'column comment and attrs';
114 my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
115 my @type_columns = grep /^a/, $rsrc->columns;
116 my @without_precision = grep !/_with_precision\z/, @type_columns;
117 my @with_precision = grep /_with_precision\z/, @type_columns;
120 apply { s/_with_precision\z// } @with_precision
123 for my $col (@without_precision) {
124 my ($data_type) = $col =~ /^an?_(.*)/;
125 ($data_type = uc $data_type) =~ s/_/ /g;
127 ok((not exists $rsrc->column_info($col)->{size}),
129 (exists $with_precision{$col} ? 'without precision ' : '') .
130 "has no 'size' column_info");
133 for my $col (@with_precision) {
134 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
135 ($data_type = uc $data_type) =~ s/_/ /g;
136 my $size = $rsrc->column_info($col)->{size};
139 "$data_type with precision has a correct 'size' column_info";
142 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
143 'size for NUMERIC(precision, scale) is correct';
145 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
146 'size for DECIMAL(precision, scale) is correct';
151 if( !$dsn || !$user ) {
152 $tester->skip_tests('You need to set the DBICTEST_PG_DSN, _USER, and _PASS environment variables');
155 $tester->run_tests();