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
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)
90 # XXX figure out what to do with DECIMAL(precision, scale) aka
91 # NUMERIC(precision, scale)
93 drop => [ qw/ pg_loader_test1 pg_loader_test2 / ],
96 my ($schema, $monikers, $classes) = @_;
98 my $class = $classes->{pg_loader_test1};
99 my $filename = $schema->_loader->_get_dump_filename($class);
102 local ($/, @ARGV) = (undef, $filename);
106 like $code, qr/^=head1 NAME\n\n^$class - The Table\n\n^=cut\n/m,
109 like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
110 'column comment and attrs';
112 my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
113 my @type_columns = grep $_ ne 'id', $rsrc->columns;
114 my @without_precision = grep !/_with_precision\z/, @type_columns;
115 my @with_precision = grep /_with_precision\z/, @type_columns;
118 apply { s/_with_precision\z// } @with_precision
121 for my $col (@without_precision) {
122 my ($data_type) = $col =~ /^an?_(.*)/;
123 ($data_type = uc $data_type) =~ s/_/ /g;
125 ok((not exists $rsrc->column_info($col)->{size}),
127 (exists $with_precision{$col} ? 'without precision ' : '') .
128 "has no 'size' column_info");
131 for my $col (@with_precision) {
132 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
133 ($data_type = uc $data_type) =~ s/_/ /g;
134 my $size = $rsrc->column_info($col)->{size};
137 "$data_type with precision has a correct 'size' column_info";
143 if( !$dsn || !$user ) {
144 $tester->skip_tests('You need to set the DBICTEST_PG_DSN, _USER, and _PASS environment variables');
147 $tester->run_tests();