Improve trigger 'scope' attribute support (RT#119997)
[dbsrgits/SQL-Translator.git] / t / 55-oracle-producer.t
CommitLineData
b307a0db 1#!/usr/bin/perl
2# vim: set ft=perl:
3
4use strict;
5use warnings;
6use Test::More;
7
8use SQL::Translator::Schema::Constants;
9use SQL::Translator::Schema::Table;
10use SQL::Translator::Schema::Field;
11use SQL::Translator::Schema::Constraint;
12use SQL::Translator::Producer::Oracle;
13
14{
15 my $table1 = SQL::Translator::Schema::Table->new( name => 'table1' );
16
17 my $table1_field1 = $table1->add_field(
18 name => 'fk_col1',
19 data_type => 'NUMBER',
20 size => 6,
21 default_value => undef,
22 is_auto_increment => 0,
23 is_nullable => 0,
24 is_foreign_key => 1,
25 is_unique => 0
26 );
27
28 my $table1_field2 = $table1->add_field(
29 name => 'fk_col2',
30 data_type => 'VARCHAR',
31 size => 64,
32 default_value => undef,
33 is_auto_increment => 0,
34 is_nullable => 0,
35 is_foreign_key => 1,
36 is_unique => 0
37 );
38
39 my $table2 = SQL::Translator::Schema::Table->new( name => 'table2' );
40
41 my $table2_field1 = $table2->add_field(
42 name => 'fk_col1',
43 data_type => 'NUMBER',
44 size => 6,
45 default_value => undef,
46 is_auto_increment => 0,
47 is_nullable => 0,
48 is_foreign_key => 0,
49 is_unique => 0
50 );
51
52 my $table2_field2 = $table2->add_field(
53 name => 'fk_col2',
54 data_type => 'VARCHAR',
55 size => 64,
56 default_value => undef,
57 is_auto_increment => 0,
58 is_nullable => 0,
59 is_foreign_key => 0,
60 is_unique => 0
61 );
62
63 my $constraint1 = $table1->add_constraint(
64 name => 'foo',
65 fields => [qw/ fk_col1 fk_col2 /],
66 reference_fields => [qw/ fk_col1 fk_col2 /],
67 reference_table => 'table2',
68 type => FOREIGN_KEY,
69 );
70
71 my ($table1_def, $fk1_def, $trigger1_def,
72 $index1_def, $constraint1_def
73 ) = SQL::Translator::Producer::Oracle::create_table($table1);
74
75 is_deeply(
76 $fk1_def,
77 [ 'ALTER TABLE table1 ADD CONSTRAINT table1_fk_col1_fk_col2_fk FOREIGN KEY (fk_col1, fk_col2) REFERENCES table2 (fk_col1, fk_col2)'
78 ],
79 'correct "CREATE CONSTRAINT" SQL'
80 );
81}
82
83done_testing();