File: make_dbictest_db_with_unique.pm

package info (click to toggle)
libdbix-class-schema-loader-perl 0.07053-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,464 kB
  • sloc: perl: 11,520; sh: 544; makefile: 4
file content (70 lines) | stat: -rw-r--r-- 2,119 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package make_dbictest_db_with_unique;

use strict;
use warnings;
use DBI;
use dbixcsl_test_dir qw/$tdir/;


eval { require DBD::SQLite };
my $class = $@ ? 'SQLite2' : 'SQLite';

my $fn = "$tdir/dbictest_with_unique.db";

unlink($fn);
our $dsn = "dbi:$class:dbname=$fn";
my $dbh = DBI->connect($dsn);
$dbh->do('PRAGMA SYNCHRONOUS = OFF');

$dbh->do($_) for (
    q|CREATE TABLE foos (
        fooid INTEGER PRIMARY KEY,
        footext TEXT
      )|,
    q|CREATE TABLE bar (
        barid INTEGER PRIMARY KEY,
        foo_id INTEGER NOT NULL REFERENCES foos (fooid)
      )|,
    q|CREATE TABLE bazs (
        bazid INTEGER PRIMARY KEY,
        baz_num INTEGER NOT NULL UNIQUE,
        stations_visited_id INTEGER REFERENCES stations_visited (id)
      )|,
    q|CREATE TABLE quuxs (
        quuxid INTEGER PRIMARY KEY,
        baz_id INTEGER NOT NULL UNIQUE,
        FOREIGN KEY (baz_id) REFERENCES bazs (baz_num)
      )|,
    q|CREATE TABLE stations_visited (
        id INTEGER PRIMARY KEY,
        quuxs_id INTEGER REFERENCES quuxs (quuxid)
      )|,
    q|CREATE TABLE RouteChange (
        id INTEGER PRIMARY KEY,
        QuuxsId INTEGER REFERENCES quuxs (quuxid),
        Foo2Bar INTEGER
      )|,
    q|CREATE TABLE email (
        id INTEGER PRIMARY KEY,
        to_id INTEGER REFERENCES foos (fooid),
        from_id INTEGER REFERENCES foos (fooid)
      )|,
    q|INSERT INTO foos VALUES (1,'Foos text for number 1')|,
    q|INSERT INTO foos VALUES (2,'Foos record associated with the Bar with barid 3')|,
    q|INSERT INTO foos VALUES (3,'Foos text for number 3')|,
    q|INSERT INTO foos VALUES (4,'Foos text for number 4')|,
    q|INSERT INTO bar VALUES (1,4)|,
    q|INSERT INTO bar VALUES (2,3)|,
    q|INSERT INTO bar VALUES (3,2)|,
    q|INSERT INTO bar VALUES (4,1)|,
    q|INSERT INTO bazs VALUES (1,20,1)|,
    q|INSERT INTO bazs VALUES (2,19,1)|,
    q|INSERT INTO quuxs VALUES (1,20)|,
    q|INSERT INTO quuxs VALUES (2,19)|,
    q|INSERT INTO stations_visited VALUES (1,1)|,
    q|INSERT INTO RouteChange VALUES (1,1,3)|,
);

END { unlink($fn) unless $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}; }

1;