6b2e3f24a4adadd9e0a7ce2d5bed325c08c6abf7
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Setup.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 my $dsn = "dbi:SQLite:${db_file}";
12
13 my $schema = DBICTest::Schema->compose_connection('DBICTest' => $dsn);
14
15 $schema->storage->on_connect_do([ "PRAGMA synchronous = OFF" ]);
16
17 my $dbh = $schema->storage->dbh;
18
19 open IN, "t/lib/sqlite.sql";
20
21 my $sql;
22
23 { local $/ = undef; $sql = <IN>; }
24
25 close IN;
26
27 $dbh->do($_) for split(/\n\n/, $sql);
28
29 $schema->storage->dbh->do("PRAGMA synchronous = OFF");
30
31 $schema->populate('Artist', [
32   [ qw/artistid name/ ],
33   [ 1, 'Caterwauler McCrae' ],
34   [ 2, 'Random Boy Band' ],
35   [ 3, 'We Are Goth' ],
36 ]);
37
38 $schema->populate('CD', [
39   [ qw/cdid artist title year/ ],
40   [ 1, 1, "Spoonful of bees", 1999 ],
41   [ 2, 1, "Forkful of bees", 2001 ],
42   [ 3, 1, "Caterwaulin' Blues", 1997 ],
43   [ 4, 2, "Generic Manufactured Singles", 2001 ],
44   [ 5, 3, "Come Be Depressed With Us", 1998 ],
45 ]);
46
47 $schema->populate('LinerNotes', [
48   [ qw/liner_id notes/ ],
49   [ 2, "Buy Whiskey!" ],
50   [ 4, "Buy Merch!" ],
51   [ 5, "Kill Yourself!" ],
52 ]);
53
54 $schema->populate('Tag', [
55   [ qw/tagid cd tag/ ],
56   [ 1, 1, "Blue" ],
57   [ 2, 2, "Blue" ],
58   [ 3, 3, "Blue" ],
59   [ 4, 5, "Blue" ],
60   [ 5, 2, "Cheesy" ],
61   [ 6, 4, "Cheesy" ],
62   [ 7, 5, "Cheesy" ],
63   [ 8, 2, "Shiny" ],
64   [ 9, 4, "Shiny" ],
65 ]);
66
67 $schema->populate('TwoKeys', [
68   [ qw/artist cd/ ],
69   [ 1, 1 ],
70   [ 1, 2 ],
71   [ 2, 2 ],
72 ]);
73
74 $schema->populate('FourKeys', [
75   [ qw/foo bar hello goodbye/ ],
76   [ 1, 2, 3, 4 ],
77   [ 5, 4, 3, 6 ],
78 ]);
79
80 $schema->populate('OneKey', [
81   [ qw/id artist cd/ ],
82   [ 1, 1, 1 ],
83   [ 2, 1, 2 ],
84   [ 3, 2, 2 ],
85 ]);
86
87 $schema->populate('SelfRef', [
88   [ qw/id name/ ],
89   [ 1, 'First' ],
90   [ 2, 'Second' ],
91 ]);
92
93 $schema->populate('SelfRefAlias', [
94   [ qw/self_ref alias/ ],
95   [ 1, 2 ]
96 ]);
97
98 $schema->populate('ArtistUndirectedMap', [
99   [ qw/id1 id2/ ],
100   [ 1, 2 ]
101 ]);
102
103 $schema->populate('Producer', [
104   [ qw/producerid name/ ],
105   [ 1, 'Matt S Trout' ],
106   [ 2, 'Bob The Builder' ],
107   [ 3, 'Fred The Phenotype' ],
108 ]);
109
110 $schema->populate('CD_to_Producer', [
111   [ qw/cd producer/ ],
112   [ 1, 1 ],
113   [ 1, 2 ],
114   [ 1, 3 ],
115 ]);
116
117 $schema->populate('TreeLike', [
118   [ qw/id parent name/ ],
119   [ 1, 0, 'foo'  ],
120   [ 2, 1, 'bar'  ],
121   [ 3, 2, 'baz'  ],
122   [ 4, 3, 'quux' ],
123 ]);
124
125 1;