118800b7266a10d6ace440c5561f7fe90aea03bb
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / make_dbictest_db.pm
1 package make_dbictest_db;
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.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 foo (
19         fooid INTEGER PRIMARY KEY,
20         footext TEXT DEFAULT 'footext',
21         foodt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
22       )|,
23     q|CREATE TABLE bar (
24         barid INTEGER PRIMARY KEY,
25         fooref INTEGER REFERENCES foo(fooid)
26       )|,
27     q|INSERT INTO foo (fooid, footext) VALUES (1,'Foo text for number 1')|,
28     q|INSERT INTO foo (fooid, footext) VALUES (2,'Foo record associated with the Bar with barid 3')|,
29     q|INSERT INTO foo (fooid, footext) VALUES (3,'Foo text for number 3')|,
30     q|INSERT INTO foo (fooid, footext) VALUES (4,'Foo text for number 4')|,
31     q|INSERT INTO bar VALUES (1,4)|,
32     q|INSERT INTO bar VALUES (2,3)|,
33     q|INSERT INTO bar VALUES (3,2)|,
34     q|INSERT INTO bar VALUES (4,1)|,
35 );
36
37 END { unlink($fn); }
38
39 1;