Add new column with a default to Artist, adjust tests as necessary (no functional...
[dbsrgits/DBIx-Class.git] / t / bindtype_columns.t
CommitLineData
6e399b4f 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
9fdf90df 8my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
6e399b4f 9
9fdf90df 10plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $dbuser);
12
13plan tests => 3;
14
77d76d0f 15my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
9fdf90df 16
eda28767 17my $dbh = $schema->storage->dbh;
9fdf90df 18
bb452615 19{
20 local $SIG{__WARN__} = sub {};
21 $dbh->do('DROP TABLE IF EXISTS artist');
22 $dbh->do(qq[
23 CREATE TABLE artist
24 (
25 artistid serial NOT NULL PRIMARY KEY,
26 media bytea NOT NULL,
39da2a2b 27 name varchar NULL,
28 rank integer NOT NULL DEFAULT '13'
bb452615 29 );
30 ],{ RaiseError => 1, PrintError => 1 });
31}
9fdf90df 32
eda28767 33$schema->class('Artist')->load_components(qw/
9fdf90df 34
35 PK::Auto
36 Core
37/);
38
eda28767 39$schema->class('Artist')->add_columns(
6e399b4f 40
9fdf90df 41 "media", {
6e399b4f 42
9fdf90df 43 data_type => "bytea",
7036ea60 44 is_nullable => 0,
9fdf90df 45 },
46);
47
48# test primary key handling
49my $big_long_string = 'abcd' x 250000;
50
eda28767 51my $new = $schema->resultset('Artist')->create({ media => $big_long_string });
9fdf90df 52
53ok($new->artistid, "Created a blob row");
54is($new->media, $big_long_string, "Set the blob correctly.");
55
eda28767 56my $rs = $schema->resultset('Artist')->find({artistid=>$new->artistid});
9fdf90df 57
58is($rs->get_column('media'), $big_long_string, "Created the blob correctly.");
59
60$dbh->do("DROP TABLE artist");
61
62
6e399b4f 63