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