add accessor to rels for DBICTest::Schema::Tag and DBICTest::Schema::Track
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Setup.pm
CommitLineData
4d9d84d5 1use strict;
2use warnings;
3use DBICTest::Schema;
4
5my $db_file = "t/var/DBIxClass.db";
6
7unlink($db_file) if -e $db_file;
8unlink($db_file . "-journal") if -e $db_file . "-journal";
9mkdir("t/var") unless -d "t/var";
10
11my $dsn = "dbi:SQLite:${db_file}";
12
13my $schema = DBICTest::Schema->compose_connection('DBICTest' => $dsn);
14
15my $dbh = DBI->connect($dsn);
16
17my $sql = <<EOSQL;
18CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
19
20CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL,
21 title VARCHAR, year VARCHAR);
22
23CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR);
24
25CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
26 position INTEGER NOT NULL, title VARCHAR);
27
28CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
29 tag VARCHAR);
30
31CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL,
32 PRIMARY KEY (artist, cd) );
33
34CREATE 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) );
37
38CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
39 artist INTEGER NOT NULL, cd INTEGER NOT NULL );
40
41CREATE TABLE self_ref (id INTEGER NOT NULL PRIMARY KEY,
42 name VARCHAR );
43
44CREATE TABLE self_ref_alias (self_ref INTEGER NOT NULL, alias INTEGER NOT NULL,
45 PRIMARY KEY( self_ref, alias ) );
46
5efe4c79 47CREATE TABLE artist_undirected_map (id1 INTEGER NOT NULL, id2 INTEGER NOT NULL, PRIMARY KEY(id1, id2));
48
4d9d84d5 49CREATE TABLE producer (producerid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
50
51CREATE TABLE cd_to_producer (cd INTEGER NOT NULL, producer INTEGER NOT NULL);
52
53INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
54
55INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band');
56
57INSERT INTO artist (artistid, name) VALUES (3, 'We Are Goth');
58
59INSERT INTO cd (cdid, artist, title, year)
60 VALUES (1, 1, "Spoonful of bees", 1999);
61
62INSERT INTO cd (cdid, artist, title, year)
63 VALUES (2, 1, "Forkful of bees", 2001);
64
65INSERT INTO cd (cdid, artist, title, year)
66 VALUES (3, 1, "Caterwaulin' Blues", 1997);
67
68INSERT INTO cd (cdid, artist, title, year)
69 VALUES (4, 2, "Generic Manufactured Singles", 2001);
70
71INSERT INTO cd (cdid, artist, title, year)
72 VALUES (5, 3, "Come Be Depressed With Us", 1998);
73
74INSERT INTO liner_notes (liner_id, notes)
75 VALUES (2, "Buy Whiskey!");
76
77INSERT INTO liner_notes (liner_id, notes)
78 VALUES (4, "Buy Merch!");
79
80INSERT INTO liner_notes (liner_id, notes)
81 VALUES (5, "Kill Yourself!");
82
83INSERT INTO tags (tagid, cd, tag) VALUES (1, 1, "Blue");
84
85INSERT INTO tags (tagid, cd, tag) VALUES (2, 2, "Blue");
86
87INSERT INTO tags (tagid, cd, tag) VALUES (3, 3, "Blue");
88
89INSERT INTO tags (tagid, cd, tag) VALUES (4, 5, "Blue");
90
91INSERT INTO tags (tagid, cd, tag) VALUES (5, 2, "Cheesy");
92
93INSERT INTO tags (tagid, cd, tag) VALUES (6, 4, "Cheesy");
94
95INSERT INTO tags (tagid, cd, tag) VALUES (7, 5, "Cheesy");
96
97INSERT INTO tags (tagid, cd, tag) VALUES (8, 2, "Shiny");
98
99INSERT INTO tags (tagid, cd, tag) VALUES (9, 4, "Shiny");
100
101INSERT INTO twokeys (artist, cd) VALUES (1, 1);
102
103INSERT INTO twokeys (artist, cd) VALUES (1, 2);
104
105INSERT INTO twokeys (artist, cd) VALUES (2, 2);
106
107INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (1, 2, 3, 4);
108
109INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (5, 4, 3, 6);
110
111INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1);
112
113INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2);
114
115INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2);
116
117INSERT INTO self_ref (id, name) VALUES (1, 'First');
118
119INSERT INTO self_ref (id, name) VALUES (2, 'Second');
120
121INSERT INTO self_ref_alias (self_ref, alias) VALUES (1, 2);
122
5efe4c79 123INSERT INTO artist_undirected_map (id1, id2) VALUES (1, 2);
124
4d9d84d5 125INSERT INTO producer (producerid, name) VALUES (1, 'Matt S Trout');
126
127INSERT INTO cd_to_producer (cd, producer) VALUES (1, 1);
128
129EOSQL
130
131$dbh->do($_) for split(/\n\n/, $sql);
132
133$schema->storage->dbh->do("PRAGMA synchronous = OFF");
134
1351;