Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class-Historic.git] / t / run / 12pg.tl
CommitLineData
0567538f 1sub run_tests {
1edaf6fe 2my $schema = shift;
0567538f 3my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
4
5#warn "$dsn $user $pass";
6
7plan skip_all, 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
b6b65a3e 8 . ' (note: creates and drops a table named artist!)' unless ($dsn && $user);
0567538f 9
fc22fbac 10plan tests => 4;
0567538f 11
70fe6d6e 12DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
0567538f 13
a953d8d9 14my $dbh = PgTest->schema->storage->dbh;
4d272ce5 15PgTest->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));");
0567538f 18
843f8ecd 19PgTest::Artist->load_components('PK::Auto');
0567538f 20
21my $new = PgTest::Artist->create({ name => 'foo' });
22
b6b65a3e 23is($new->artistid, 1, "Auto-PK worked");
24
25$new = PgTest::Artist->create({ name => 'bar' });
26
27is($new->artistid, 2, "Auto-PK worked");
28
a953d8d9 29my $test_type_info = {
30 'artistid' => {
103e3e03 31 'data_type' => 'integer',
32 'is_nullable' => 0,
fc22fbac 33 'size' => 4,
a953d8d9 34 },
35 'name' => {
103e3e03 36 'data_type' => 'character varying',
37 'is_nullable' => 1,
fc22fbac 38 'size' => 255,
39 'default_value' => undef,
103e3e03 40 },
41 'charfield' => {
42 'data_type' => 'character',
a953d8d9 43 'is_nullable' => 1,
fc22fbac 44 'size' => 10,
45 'default_value' => undef,
103e3e03 46 },
a953d8d9 47};
48
fc22fbac 49
4d272ce5 50my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
fc22fbac 51my $artistid_defval = delete $type_info->{artistid}->{default_value};
52like($artistid_defval,
4d272ce5 53 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
fc22fbac 54 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
55is_deeply($type_info, $test_type_info,
56 'columns_info_for - column data types');
a953d8d9 57
4d272ce5 58$dbh->do("DROP TABLE testschema.artist;");
59$dbh->do("DROP SCHEMA testschema;");
0567538f 60
61}
62
631;