5 use base qw/DBIx::Class::Core/;
7 my $db_file = "t/var/DBIxClass.db";
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";
13 __PACKAGE__->connection("dbi:SQLite:${db_file}");
15 my $dbh = __PACKAGE__->_get_dbh;
18 CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
20 CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL,
21 title VARCHAR, year VARCHAR);
23 CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR);
25 CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
26 position INTEGER NOT NULL, title VARCHAR);
28 CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
31 CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL,
32 PRIMARY KEY (artist, cd) );
34 CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
35 artist INTEGER NOT NULL, cd INTEGER NOT NULL );
37 INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
39 INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band');
41 INSERT INTO artist (artistid, name) VALUES (3, 'We Are Goth');
43 INSERT INTO cd (cdid, artist, title, year)
44 VALUES (1, 1, "Spoonful of bees", 1999);
46 INSERT INTO cd (cdid, artist, title, year)
47 VALUES (2, 1, "Forkful of bees", 2001);
49 INSERT INTO cd (cdid, artist, title, year)
50 VALUES (3, 1, "Caterwaulin' Blues", 1997);
52 INSERT INTO cd (cdid, artist, title, year)
53 VALUES (4, 2, "Generic Manufactured Singles", 2001);
55 INSERT INTO cd (cdid, artist, title, year)
56 VALUES (5, 3, "Come Be Depressed With Us", 1998);
58 INSERT INTO liner_notes (liner_id, notes)
59 VALUES (2, "Buy Whiskey!");
61 INSERT INTO liner_notes (liner_id, notes)
62 VALUES (4, "Buy Merch!");
64 INSERT INTO liner_notes (liner_id, notes)
65 VALUES (5, "Kill Yourself!");
67 INSERT INTO tags (tagid, cd, tag) VALUES (1, 1, "Blue");
69 INSERT INTO tags (tagid, cd, tag) VALUES (2, 2, "Blue");
71 INSERT INTO tags (tagid, cd, tag) VALUES (3, 3, "Blue");
73 INSERT INTO tags (tagid, cd, tag) VALUES (4, 5, "Blue");
75 INSERT INTO tags (tagid, cd, tag) VALUES (5, 2, "Cheesy");
77 INSERT INTO tags (tagid, cd, tag) VALUES (6, 4, "Cheesy");
79 INSERT INTO tags (tagid, cd, tag) VALUES (7, 5, "Cheesy");
81 INSERT INTO tags (tagid, cd, tag) VALUES (8, 2, "Shiny");
83 INSERT INTO tags (tagid, cd, tag) VALUES (9, 4, "Shiny");
85 INSERT INTO twokeys (artist, cd) VALUES (1, 1);
87 INSERT INTO twokeys (artist, cd) VALUES (1, 2);
89 INSERT INTO twokeys (artist, cd) VALUES (2, 2);
91 INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1);
93 INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2);
95 INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2);
98 $dbh->do($_) for split(/\n\n/, $sql);
100 package DBICTest::LinerNotes;
104 DBICTest::LinerNotes->table('liner_notes');
105 DBICTest::LinerNotes->add_columns(qw/liner_id notes/);
106 DBICTest::LinerNotes->set_primary_key('liner_id');
108 package DBICTest::Tag;
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');
117 package DBICTest::Track;
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');
126 package DBICTest::CD;
130 DBICTest::CD->table('cd');
131 DBICTest::CD->add_columns(qw/cdid artist title year/);
132 DBICTest::CD->set_primary_key('trackid');
134 #DBICTest::CD->has_many(tracks => 'SweetTest::Track');
135 #DBICTest::CD->has_many(tags => 'SweetTest::Tag');
136 #DBICTest::CD->has_a(artist => 'SweetTest::Artist');
138 #DBICTest::CD->might_have(liner_notes => 'SweetTest::LinerNotes' => qw/notes/);
140 package DBICTest::Artist;
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');
151 package DBICTest::TwoKeys;
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');
161 package DBICTest::OneKey;
165 DBICTest::OneKey->table('onekey');
166 DBICTest::OneKey->add_columns(qw/id artist cd/);
167 DBICTest::TwoKeys->set_primary_key('id');