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