First of a two-parter :)
[dbsrgits/DBIx-Class-Historic.git] / t / lib / DBICTest.pm
1 package DBICTest;
2
3 use strict;
4 use warnings;
5 use base qw/DBIx::Class::Core/;
6
7 my $db_file = "t/var/DBIxClass.db";
8
9 unlink($db_file) if -e $db_file;
10 unlink($db_file . "-journal") if -e $db_file . "-journal";
11 mkdir("t/var") unless -d "t/var";
12
13 __PACKAGE__->connection("dbi:SQLite:${db_file}");
14
15 my $dbh = __PACKAGE__->_get_dbh;
16
17 my $sql = <<EOSQL;
18 CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
19
20 CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL,
21                      title VARCHAR, year VARCHAR);
22
23 CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR);
24
25 CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
26                        position INTEGER NOT NULL, title VARCHAR);
27
28 CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
29                       tag VARCHAR);
30
31 CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL,
32                       PRIMARY KEY (artist, cd) );
33
34 CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
35                       artist INTEGER NOT NULL, cd INTEGER NOT NULL );
36
37 INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
38
39 INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band');
40
41 INSERT INTO artist (artistid, name) VALUES (3, 'We Are Goth');
42
43 INSERT INTO cd (cdid, artist, title, year)
44     VALUES (1, 1, "Spoonful of bees", 1999);
45
46 INSERT INTO cd (cdid, artist, title, year)
47     VALUES (2, 1, "Forkful of bees", 2001);
48
49 INSERT INTO cd (cdid, artist, title, year)
50     VALUES (3, 1, "Caterwaulin' Blues", 1997);
51
52 INSERT INTO cd (cdid, artist, title, year)
53     VALUES (4, 2, "Generic Manufactured Singles", 2001);
54
55 INSERT INTO cd (cdid, artist, title, year)
56     VALUES (5, 3, "Come Be Depressed With Us", 1998);
57
58 INSERT INTO liner_notes (liner_id, notes)
59     VALUES (2, "Buy Whiskey!");
60
61 INSERT INTO liner_notes (liner_id, notes)
62     VALUES (4, "Buy Merch!");
63
64 INSERT INTO liner_notes (liner_id, notes)
65     VALUES (5, "Kill Yourself!");
66
67 INSERT INTO tags (tagid, cd, tag) VALUES (1, 1, "Blue");
68
69 INSERT INTO tags (tagid, cd, tag) VALUES (2, 2, "Blue");
70
71 INSERT INTO tags (tagid, cd, tag) VALUES (3, 3, "Blue");
72
73 INSERT INTO tags (tagid, cd, tag) VALUES (4, 5, "Blue");
74
75 INSERT INTO tags (tagid, cd, tag) VALUES (5, 2, "Cheesy");
76
77 INSERT INTO tags (tagid, cd, tag) VALUES (6, 4, "Cheesy");
78
79 INSERT INTO tags (tagid, cd, tag) VALUES (7, 5, "Cheesy");
80
81 INSERT INTO tags (tagid, cd, tag) VALUES (8, 2, "Shiny");
82
83 INSERT INTO tags (tagid, cd, tag) VALUES (9, 4, "Shiny");
84
85 INSERT INTO twokeys (artist, cd) VALUES (1, 1);
86
87 INSERT INTO twokeys (artist, cd) VALUES (1, 2);
88
89 INSERT INTO twokeys (artist, cd) VALUES (2, 2);
90
91 INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1);
92
93 INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2);
94
95 INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2);
96 EOSQL
97
98 $dbh->do($_) for split(/\n\n/, $sql);
99
100 package DBICTest::LinerNotes;
101
102 use base 'DBICTest';
103
104 DBICTest::LinerNotes->table('liner_notes');
105 DBICTest::LinerNotes->add_columns(qw/liner_id notes/);
106 DBICTest::LinerNotes->set_primary_key('liner_id');
107
108 package DBICTest::Tag;
109
110 use base 'DBICTest';
111
112 DBICTest::Tag->table('tags');
113 DBICTest::Tag->add_columns(qw/tagid cd tag/);
114 DBICTest::Tag->set_primary_key('tagid');
115 #DBICTest::Tag->has_a(cd => 'SweetTest::CD');
116
117 package DBICTest::Track;
118
119 use base 'DBICTest';
120
121 DBICTest::Track->table('track');
122 DBICTest::Track->add_columns(qw/trackid cd position title/);
123 DBICTest::Track->set_primary_key('trackid');
124 #DBICTest::Track->has_a(cd => 'SweetTest::CD');
125
126 package DBICTest::CD;
127
128 use base 'DBICTest';
129
130 DBICTest::CD->table('cd');
131 DBICTest::CD->add_columns(qw/cdid artist title year/);
132 DBICTest::CD->set_primary_key('trackid');
133
134 #DBICTest::CD->has_many(tracks => 'SweetTest::Track');
135 #DBICTest::CD->has_many(tags => 'SweetTest::Tag');
136 #DBICTest::CD->has_a(artist => 'SweetTest::Artist');
137
138 #DBICTest::CD->might_have(liner_notes => 'SweetTest::LinerNotes' => qw/notes/);
139
140 package DBICTest::Artist;
141
142 use base 'DBICTest';
143
144 DBICTest::Artist->table('artist');
145 DBICTest::Artist->add_columns(qw/artistid name/);
146 DBICTest::Artist->set_primary_key('artistid');
147 #DBICTest::Artist->has_many(cds => 'SweetTest::CD');
148 #DBICTest::Artist->has_many(twokeys => 'SweetTest::TwoKeys');
149 #DBICTest::Artist->has_many(onekeys => 'SweetTest::OneKey');
150
151 package DBICTest::TwoKeys;
152
153 use base 'DBICTest';
154
155 DBICTest::TwoKeys->table('twokeys');
156 DBICTest::TwoKeys->add_columns(qw/artist cd/);
157 DBICTest::TwoKeys->set_primary_key(qw/artist cd/);
158 #DBICTest::TwoKeys->has_a(artist => 'SweetTest::Artist');
159 #DBICTest::TwoKeys->has_a(cd => 'SweetTest::CD');
160
161 package DBICTest::OneKey;
162
163 use base 'DBICTest';
164
165 DBICTest::OneKey->table('onekey');
166 DBICTest::OneKey->add_columns(qw/id artist cd/);
167 DBICTest::TwoKeys->set_primary_key('id');
168
169 1;