8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
10 #warn "$dsn $user $pass";
12 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
13 . ' (note: creates and drops a table named artist!)' unless ($dsn && $user);
17 DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
19 my $dbh = PgTest->schema->storage->dbh;
20 PgTest->schema->source("Artist")->name("testschema.artist");
21 $dbh->do("CREATE SCHEMA testschema;");
22 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
24 PgTest::Artist->load_components('PK::Auto');
26 my $new = PgTest::Artist->create({ name => 'foo' });
28 is($new->artistid, 1, "Auto-PK worked");
30 $new = PgTest::Artist->create({ name => 'bar' });
32 is($new->artistid, 2, "Auto-PK worked");
34 my $test_type_info = {
36 'data_type' => 'integer',
41 'data_type' => 'character varying',
44 'default_value' => undef,
47 'data_type' => 'character',
50 'default_value' => undef,
55 my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
56 my $artistid_defval = delete $type_info->{artistid}->{default_value};
57 like($artistid_defval,
58 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
59 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
60 is_deeply($type_info, $test_type_info,
61 'columns_info_for - column data types');
63 $dbh->do("DROP TABLE testschema.artist;");
64 $dbh->do("DROP SCHEMA testschema;");