Merge 'DBIx-Class-current' into 'datetime'
[dbsrgits/DBIx-Class.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'
0b88a5bb 8 . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
0567538f 9
0b88a5bb 10plan tests => 8;
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;");
0b88a5bb 17
18$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
19ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
0567538f 20
843f8ecd 21PgTest::Artist->load_components('PK::Auto');
0567538f 22
23my $new = PgTest::Artist->create({ name => 'foo' });
24
b6b65a3e 25is($new->artistid, 1, "Auto-PK worked");
26
27$new = PgTest::Artist->create({ name => 'bar' });
28
29is($new->artistid, 2, "Auto-PK worked");
30
a953d8d9 31my $test_type_info = {
32 'artistid' => {
103e3e03 33 'data_type' => 'integer',
34 'is_nullable' => 0,
fc22fbac 35 'size' => 4,
a953d8d9 36 },
37 'name' => {
103e3e03 38 'data_type' => 'character varying',
39 'is_nullable' => 1,
0b88a5bb 40 'size' => 100,
fc22fbac 41 'default_value' => undef,
103e3e03 42 },
43 'charfield' => {
44 'data_type' => 'character',
a953d8d9 45 'is_nullable' => 1,
fc22fbac 46 'size' => 10,
47 'default_value' => undef,
103e3e03 48 },
a953d8d9 49};
50
fc22fbac 51
4d272ce5 52my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
fc22fbac 53my $artistid_defval = delete $type_info->{artistid}->{default_value};
54like($artistid_defval,
4d272ce5 55 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
fc22fbac 56 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
57is_deeply($type_info, $test_type_info,
58 'columns_info_for - column data types');
a953d8d9 59
0b88a5bb 60my $name_info = PgTest::Casecheck->column_info( 'name' );
61is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
62
63my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
64is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
65
66my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
67is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
68
4d272ce5 69$dbh->do("DROP TABLE testschema.artist;");
0b88a5bb 70$dbh->do("DROP TABLE testschema.casecheck;");
4d272ce5 71$dbh->do("DROP SCHEMA testschema;");
0567538f 72
73}
74
751;