6f75ad36c7794f03b94e4cfa9fb8a5f04dd3c719
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / make_dbictest_db_with_unique.pm
1 package make_dbictest_db_with_unique;
2
3 use strict;
4 use warnings;
5 use DBI;
6
7 eval { require DBD::SQLite };
8 my $class = $@ ? 'SQLite2' : 'SQLite';
9
10 my $fn = './t/dbictest_with_unique.db';
11
12 unlink($fn);
13 our $dsn = "dbi:$class:dbname=$fn";
14 my $dbh = DBI->connect($dsn);
15 $dbh->do('PRAGMA SYNCHRONOUS = OFF');
16
17 $dbh->do($_) for (
18     q|CREATE TABLE foos (
19         fooid INTEGER PRIMARY KEY,
20         footext TEXT
21       )|,
22     q|CREATE TABLE bar (
23         barid INTEGER PRIMARY KEY,
24         foo_id INTEGER NOT NULL REFERENCES foos (fooid)
25       )|,
26     q|CREATE TABLE bazs (
27         bazid INTEGER PRIMARY KEY,
28         baz_num INTEGER NOT NULL UNIQUE,
29         stations_visited_id INTEGER REFERENCES stations_visited (id)
30       )|,
31     q|CREATE TABLE quuxs (
32         quuxid INTEGER PRIMARY KEY,
33         baz_id INTEGER NOT NULL UNIQUE,
34         FOREIGN KEY (baz_id) REFERENCES bazs (baz_num)
35       )|,
36     q|CREATE TABLE stations_visited (
37         id INTEGER PRIMARY KEY,
38         quuxs_id INTEGER REFERENCES quuxs (quuxid)
39       )|,
40     q|CREATE TABLE RouteChange (
41         id INTEGER PRIMARY KEY,
42         QuuxsId INTEGER REFERENCES quuxs (quuxid),
43         Foo2Bar INTEGER
44       )|,
45     q|CREATE TABLE email (
46         id INTEGER PRIMARY KEY,
47         to_id INTEGER REFERENCES foos (fooid),
48         from_id INTEGER REFERENCES foos (fooid)
49       )|,
50     q|INSERT INTO foos VALUES (1,'Foos text for number 1')|,
51     q|INSERT INTO foos VALUES (2,'Foos record associated with the Bar with barid 3')|,
52     q|INSERT INTO foos VALUES (3,'Foos text for number 3')|,
53     q|INSERT INTO foos VALUES (4,'Foos text for number 4')|,
54     q|INSERT INTO bar VALUES (1,4)|,
55     q|INSERT INTO bar VALUES (2,3)|,
56     q|INSERT INTO bar VALUES (3,2)|,
57     q|INSERT INTO bar VALUES (4,1)|,
58     q|INSERT INTO bazs VALUES (1,20,1)|,
59     q|INSERT INTO bazs VALUES (2,19,1)|,
60     q|INSERT INTO quuxs VALUES (1,20)|,
61     q|INSERT INTO quuxs VALUES (2,19)|,
62     q|INSERT INTO stations_visited VALUES (1,1)|,
63     q|INSERT INTO RouteChange VALUES (1,1,3)|,
64 );
65
66 END { unlink($fn); }
67
68 1;