Commit | Line | Data |
510ca912 |
1 | package DBICTest; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use base qw/DBIx::Class::Core/; |
60786fdc |
6 | use DateTime; |
510ca912 |
7 | |
8 | my $db_file = "t/var/DBIxClass.db"; |
9 | |
10 | unlink($db_file) if -e $db_file; |
11 | unlink($db_file . "-journal") if -e $db_file . "-journal"; |
12 | mkdir("t/var") unless -d "t/var"; |
13 | |
14 | __PACKAGE__->connection("dbi:SQLite:${db_file}"); |
15 | |
16 | my $dbh = __PACKAGE__->_get_dbh; |
17 | |
18 | my $sql = <<EOSQL; |
19 | CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR); |
20 | |
21 | CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL, |
22 | title VARCHAR, year VARCHAR); |
23 | |
24 | CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR); |
25 | |
26 | CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL, |
27 | position INTEGER NOT NULL, title VARCHAR); |
28 | |
29 | CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL, |
30 | tag VARCHAR); |
31 | |
32 | CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL, |
33 | PRIMARY KEY (artist, cd) ); |
34 | |
6eec7501 |
35 | CREATE TABLE fourkeys (foo INTEGER NOT NULL, bar INTEGER NOT NULL, |
36 | hello INTEGER NOT NULL, goodbye INTEGER NOT NULL, |
37 | PRIMARY KEY (foo, bar, hello, goodbye) ); |
38 | |
510ca912 |
39 | CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY, |
40 | artist INTEGER NOT NULL, cd INTEGER NOT NULL ); |
41 | |
42 | INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae'); |
43 | |
44 | INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band'); |
45 | |
46 | INSERT INTO artist (artistid, name) VALUES (3, 'We Are Goth'); |
47 | |
48 | INSERT INTO cd (cdid, artist, title, year) |
49 | VALUES (1, 1, "Spoonful of bees", 1999); |
50 | |
51 | INSERT INTO cd (cdid, artist, title, year) |
52 | VALUES (2, 1, "Forkful of bees", 2001); |
53 | |
54 | INSERT INTO cd (cdid, artist, title, year) |
55 | VALUES (3, 1, "Caterwaulin' Blues", 1997); |
56 | |
57 | INSERT INTO cd (cdid, artist, title, year) |
58 | VALUES (4, 2, "Generic Manufactured Singles", 2001); |
59 | |
60 | INSERT INTO cd (cdid, artist, title, year) |
61 | VALUES (5, 3, "Come Be Depressed With Us", 1998); |
62 | |
63 | INSERT INTO liner_notes (liner_id, notes) |
64 | VALUES (2, "Buy Whiskey!"); |
65 | |
66 | INSERT INTO liner_notes (liner_id, notes) |
67 | VALUES (4, "Buy Merch!"); |
68 | |
69 | INSERT INTO liner_notes (liner_id, notes) |
70 | VALUES (5, "Kill Yourself!"); |
71 | |
72 | INSERT INTO tags (tagid, cd, tag) VALUES (1, 1, "Blue"); |
73 | |
74 | INSERT INTO tags (tagid, cd, tag) VALUES (2, 2, "Blue"); |
75 | |
76 | INSERT INTO tags (tagid, cd, tag) VALUES (3, 3, "Blue"); |
77 | |
78 | INSERT INTO tags (tagid, cd, tag) VALUES (4, 5, "Blue"); |
79 | |
80 | INSERT INTO tags (tagid, cd, tag) VALUES (5, 2, "Cheesy"); |
81 | |
82 | INSERT INTO tags (tagid, cd, tag) VALUES (6, 4, "Cheesy"); |
83 | |
84 | INSERT INTO tags (tagid, cd, tag) VALUES (7, 5, "Cheesy"); |
85 | |
86 | INSERT INTO tags (tagid, cd, tag) VALUES (8, 2, "Shiny"); |
87 | |
88 | INSERT INTO tags (tagid, cd, tag) VALUES (9, 4, "Shiny"); |
89 | |
90 | INSERT INTO twokeys (artist, cd) VALUES (1, 1); |
91 | |
92 | INSERT INTO twokeys (artist, cd) VALUES (1, 2); |
93 | |
94 | INSERT INTO twokeys (artist, cd) VALUES (2, 2); |
95 | |
6eec7501 |
96 | INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (1, 2, 3, 4); |
97 | |
98 | INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (5, 4, 3, 6); |
99 | |
510ca912 |
100 | INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1); |
101 | |
102 | INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2); |
103 | |
104 | INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2); |
105 | EOSQL |
106 | |
107 | $dbh->do($_) for split(/\n\n/, $sql); |
108 | |
109 | package DBICTest::LinerNotes; |
110 | |
111 | use base 'DBICTest'; |
112 | |
113 | DBICTest::LinerNotes->table('liner_notes'); |
114 | DBICTest::LinerNotes->add_columns(qw/liner_id notes/); |
115 | DBICTest::LinerNotes->set_primary_key('liner_id'); |
116 | |
117 | package DBICTest::Tag; |
118 | |
119 | use base 'DBICTest'; |
120 | |
121 | DBICTest::Tag->table('tags'); |
122 | DBICTest::Tag->add_columns(qw/tagid cd tag/); |
123 | DBICTest::Tag->set_primary_key('tagid'); |
256c505c |
124 | DBICTest::Tag->add_relationship( |
125 | cd => 'DBICTest::CD', |
126 | { 'foreign.cdid' => 'self.cd' } |
127 | ); |
510ca912 |
128 | |
129 | package DBICTest::Track; |
130 | |
131 | use base 'DBICTest'; |
132 | |
133 | DBICTest::Track->table('track'); |
134 | DBICTest::Track->add_columns(qw/trackid cd position title/); |
135 | DBICTest::Track->set_primary_key('trackid'); |
256c505c |
136 | DBICTest::Track->add_relationship( |
137 | cd => 'DBICTest::CD', |
138 | { 'foreign.cdid' => 'self.cd' } |
139 | ); |
510ca912 |
140 | |
141 | package DBICTest::CD; |
142 | |
143 | use base 'DBICTest'; |
144 | |
145 | DBICTest::CD->table('cd'); |
146 | DBICTest::CD->add_columns(qw/cdid artist title year/); |
256c505c |
147 | DBICTest::CD->set_primary_key('cdid'); |
148 | DBICTest::CD->add_relationship( |
149 | artist => 'DBICTest::Artist', |
150 | { 'foreign.artistid' => 'self.artist' } |
151 | ); |
152 | DBICTest::CD->add_relationship( |
153 | tracks => 'DBICTest::Track', |
154 | { 'foreign.cd' => 'self.cdid' } |
155 | ); |
156 | DBICTest::CD->add_relationship( |
157 | tags => 'DBICTest::Tag', |
158 | { 'foreign.cd' => 'self.cdid' } |
159 | ); |
160 | #DBICTest::CD->might_have(liner_notes => 'DBICTest::LinerNotes' => qw/notes/); |
510ca912 |
161 | |
162 | package DBICTest::Artist; |
163 | |
164 | use base 'DBICTest'; |
165 | |
166 | DBICTest::Artist->table('artist'); |
167 | DBICTest::Artist->add_columns(qw/artistid name/); |
168 | DBICTest::Artist->set_primary_key('artistid'); |
256c505c |
169 | DBICTest::Artist->add_relationship( |
170 | cds => 'DBICTest::CD', |
171 | { 'foreign.artist' => 'self.artistid' }, |
172 | { order_by => 'year' } |
173 | ); |
174 | DBICTest::Artist->add_relationship( |
175 | twokeys => 'DBICTest::TwoKeys', |
176 | { 'foreign.artist' => 'self.artistid' } |
177 | ); |
178 | DBICTest::Artist->add_relationship( |
179 | onekeys => 'DBICTest::OneKey', |
180 | { 'foreign.artist' => 'self.artistid' } |
181 | ); |
182 | |
183 | package DBICTest::OneKey; |
184 | |
185 | use base 'DBICTest'; |
186 | |
187 | DBICTest::OneKey->table('onekey'); |
188 | DBICTest::OneKey->add_columns(qw/id artist cd/); |
189 | DBICTest::OneKey->set_primary_key('id'); |
510ca912 |
190 | |
191 | package DBICTest::TwoKeys; |
192 | |
193 | use base 'DBICTest'; |
194 | |
195 | DBICTest::TwoKeys->table('twokeys'); |
196 | DBICTest::TwoKeys->add_columns(qw/artist cd/); |
197 | DBICTest::TwoKeys->set_primary_key(qw/artist cd/); |
256c505c |
198 | DBICTest::TwoKeys->add_relationship( |
199 | artist => 'DBICTest::Artist', |
200 | { 'foreign.artistid' => 'self.artist' } |
201 | ); |
202 | DBICTest::TwoKeys->add_relationship( |
203 | cd => 'DBICTest::CD', |
204 | { 'foreign.cdid' => 'self.cd' } |
205 | ); |
510ca912 |
206 | |
6eec7501 |
207 | package DBICTest::FourKeys; |
208 | |
209 | use base 'DBICTest'; |
210 | |
211 | DBICTest::FourKeys->table('fourkeys'); |
212 | DBICTest::FourKeys->add_columns(qw/foo bar hello goodbye/); |
213 | DBICTest::FourKeys->set_primary_key(qw/foo bar hello goodbye/); |
214 | |
510ca912 |
215 | 1; |