File: 55-oracle-producer.t

package info (click to toggle)
libsql-translator-perl 0.11011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,380 kB
  • sloc: perl: 251,748; sql: 3,805; xml: 233; makefile: 7
file content (83 lines) | stat: -rw-r--r-- 2,413 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
# vim: set ft=perl:

use strict;
use warnings;
use Test::More;

use SQL::Translator::Schema::Constants;
use SQL::Translator::Schema::Table;
use SQL::Translator::Schema::Field;
use SQL::Translator::Schema::Constraint;
use SQL::Translator::Producer::Oracle;

{
    my $table1 = SQL::Translator::Schema::Table->new( name => 'table1' );

    my $table1_field1 = $table1->add_field(
        name              => 'fk_col1',
        data_type         => 'NUMBER',
        size              => 6,
        default_value     => undef,
        is_auto_increment => 0,
        is_nullable       => 0,
        is_foreign_key    => 1,
        is_unique         => 0
    );

    my $table1_field2 = $table1->add_field(
        name              => 'fk_col2',
        data_type         => 'VARCHAR',
        size              => 64,
        default_value     => undef,
        is_auto_increment => 0,
        is_nullable       => 0,
        is_foreign_key    => 1,
        is_unique         => 0
    );

    my $table2 = SQL::Translator::Schema::Table->new( name => 'table2' );

    my $table2_field1 = $table2->add_field(
        name              => 'fk_col1',
        data_type         => 'NUMBER',
        size              => 6,
        default_value     => undef,
        is_auto_increment => 0,
        is_nullable       => 0,
        is_foreign_key    => 0,
        is_unique         => 0
    );

    my $table2_field2 = $table2->add_field(
        name              => 'fk_col2',
        data_type         => 'VARCHAR',
        size              => 64,
        default_value     => undef,
        is_auto_increment => 0,
        is_nullable       => 0,
        is_foreign_key    => 0,
        is_unique         => 0
    );

    my $constraint1 = $table1->add_constraint(
        name             => 'foo',
        fields           => [qw/ fk_col1 fk_col2 /],
        reference_fields => [qw/ fk_col1 fk_col2 /],
        reference_table  => 'table2',
        type             => FOREIGN_KEY,
    );

    my ($table1_def, $fk1_def, $trigger1_def,
        $index1_def, $constraint1_def
    ) = SQL::Translator::Producer::Oracle::create_table($table1);

    is_deeply(
        $fk1_def,
        [   'ALTER TABLE table1 ADD CONSTRAINT table1_fk_col1_fk_col2_fk FOREIGN KEY (fk_col1, fk_col2) REFERENCES table2 (fk_col1, fk_col2)'
        ],
        'correct "CREATE CONSTRAINT" SQL'
    );
}

done_testing();