File: make_dbictest_db_multi_m2m.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 (49 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download | duplicates (4)
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
package make_dbictest_db_multi_m2m;

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

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

my $fn = "$tdir/dbictest_multi_m2m.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 foo (
        foo_id INTEGER PRIMARY KEY
      )|,
    q|CREATE TABLE bar (
        bar_id INTEGER PRIMARY KEY
      )|,
    q|CREATE TABLE foo_bar_one (
        foo_id INTEGER NOT NULL REFERENCES foo(foo_id),
        bar_id INTEGER NOT NULL REFERENCES bar(bar_id),
        PRIMARY KEY (foo_id, bar_id)
      )|,
    q|CREATE TABLE foo_bar_two (
        foo_id INTEGER NOT NULL REFERENCES foo(foo_id),
        bar_id INTEGER NOT NULL REFERENCES bar(bar_id),
        PRIMARY KEY (foo_id, bar_id)
     )|,
    q|INSERT INTO foo (foo_id) VALUES (1)|,
    q|INSERT INTO foo (foo_id) VALUES (2)|,
    q|INSERT INTO bar (bar_id) VALUES (1)|,
    q|INSERT INTO bar (bar_id) VALUES (2)|,
    q|INSERT INTO foo_bar_one (foo_id, bar_id) VALUES (1,1)|,
    q|INSERT INTO foo_bar_one (foo_id, bar_id) VALUES (2,2)|,
    q|INSERT INTO foo_bar_two (foo_id, bar_id) VALUES (1,1)|,
    q|INSERT INTO foo_bar_two (foo_id, bar_id) VALUES (1,2)|,
    q|INSERT INTO foo_bar_two (foo_id, bar_id) VALUES (2,1)|,
    q|INSERT INTO foo_bar_two (foo_id, bar_id) VALUES (2,2)|,
);

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

1;