3 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
5 #warn "$dsn $user $pass";
7 plan skip_all, 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
8 . ' (note: creates and drops a table named artist!)' unless ($dsn && $user);
12 DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
14 my $dbh = PgTest->schema->storage->dbh;
15 PgTest->schema->source("Artist")->name("testschema.artist");
16 $dbh->do("CREATE SCHEMA testschema;");
17 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
19 PgTest::Artist->load_components('PK::Auto');
21 my $new = PgTest::Artist->create({ name => 'foo' });
23 is($new->artistid, 1, "Auto-PK worked");
25 $new = PgTest::Artist->create({ name => 'bar' });
27 is($new->artistid, 2, "Auto-PK worked");
29 my $test_type_info = {
31 'data_type' => 'integer',
36 'data_type' => 'character varying',
39 'default_value' => undef,
42 'data_type' => 'character',
45 'default_value' => undef,
50 my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
51 my $artistid_defval = delete $type_info->{artistid}->{default_value};
52 like($artistid_defval,
53 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
54 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
55 is_deeply($type_info, $test_type_info,
56 'columns_info_for - column data types');
58 $dbh->do("DROP TABLE testschema.artist;");
59 $dbh->do("DROP SCHEMA testschema;");