5 my $db_file = "t/var/DBIxClass.db";
7 unlink($db_file) if -e $db_file;
8 unlink($db_file . "-journal") if -e $db_file . "-journal";
9 mkdir("t/var") unless -d "t/var";
11 my $dsn = "dbi:SQLite:${db_file}";
13 DBICTest::Schema->compose_connection('DBICTest' => "dbi:SQLite:${db_file}");
15 my $dbh = DBI->connect($dsn);
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 fourkeys (foo INTEGER NOT NULL, bar INTEGER NOT NULL,
35 hello INTEGER NOT NULL, goodbye INTEGER NOT NULL,
36 PRIMARY KEY (foo, bar, hello, goodbye) );
38 CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
39 artist INTEGER NOT NULL, cd INTEGER NOT NULL );
41 CREATE TABLE self_ref (id INTEGER NOT NULL PRIMARY KEY,
44 CREATE TABLE self_ref_alias (self_ref INTEGER NOT NULL, alias INTEGER NOT NULL,
45 PRIMARY KEY( self_ref, alias ) );
47 INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
49 INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band');
51 INSERT INTO artist (artistid, name) VALUES (3, 'We Are Goth');
53 INSERT INTO cd (cdid, artist, title, year)
54 VALUES (1, 1, "Spoonful of bees", 1999);
56 INSERT INTO cd (cdid, artist, title, year)
57 VALUES (2, 1, "Forkful of bees", 2001);
59 INSERT INTO cd (cdid, artist, title, year)
60 VALUES (3, 1, "Caterwaulin' Blues", 1997);
62 INSERT INTO cd (cdid, artist, title, year)
63 VALUES (4, 2, "Generic Manufactured Singles", 2001);
65 INSERT INTO cd (cdid, artist, title, year)
66 VALUES (5, 3, "Come Be Depressed With Us", 1998);
68 INSERT INTO liner_notes (liner_id, notes)
69 VALUES (2, "Buy Whiskey!");
71 INSERT INTO liner_notes (liner_id, notes)
72 VALUES (4, "Buy Merch!");
74 INSERT INTO liner_notes (liner_id, notes)
75 VALUES (5, "Kill Yourself!");
77 INSERT INTO tags (tagid, cd, tag) VALUES (1, 1, "Blue");
79 INSERT INTO tags (tagid, cd, tag) VALUES (2, 2, "Blue");
81 INSERT INTO tags (tagid, cd, tag) VALUES (3, 3, "Blue");
83 INSERT INTO tags (tagid, cd, tag) VALUES (4, 5, "Blue");
85 INSERT INTO tags (tagid, cd, tag) VALUES (5, 2, "Cheesy");
87 INSERT INTO tags (tagid, cd, tag) VALUES (6, 4, "Cheesy");
89 INSERT INTO tags (tagid, cd, tag) VALUES (7, 5, "Cheesy");
91 INSERT INTO tags (tagid, cd, tag) VALUES (8, 2, "Shiny");
93 INSERT INTO tags (tagid, cd, tag) VALUES (9, 4, "Shiny");
95 INSERT INTO twokeys (artist, cd) VALUES (1, 1);
97 INSERT INTO twokeys (artist, cd) VALUES (1, 2);
99 INSERT INTO twokeys (artist, cd) VALUES (2, 2);
101 INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (1, 2, 3, 4);
103 INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (5, 4, 3, 6);
105 INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1);
107 INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2);
109 INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2);
111 INSERT INTO self_ref(id, name) VALUES (1, 'First');
113 INSERT INTO self_ref(id, name) VALUES (2, 'Second');
115 INSERT INTO self_ref_alias(self_ref, alias) VALUES (1, 2);
118 $dbh->do($_) for split(/\n\n/, $sql);