Changed to use Test::More, cleaned up syntax. Still pretty useless.
[dbsrgits/SQL-Translator.git] / t / 08postgres-to-mysql.t
1 #!/usr/local/bin/perl
2 # vim: set ft=perl:
3
4 use strict;
5 use Test::More 'no_plan'; # tests => 1;
6 use SQL::Translator;
7 use Data::Dumper;
8
9 my $create = q|
10
11 -- The cvterm module design is based on the ontology 
12
13 -- ================================================
14 -- TABLE: cv
15 -- ================================================
16
17 create table cv (
18        cv_id serial not null,
19        primary key (cv_id),
20        cvname varchar not null,
21        cvdefinition text,
22
23        unique(cvname)
24 );
25
26 -- ================================================
27 -- TABLE: cvterm
28 -- ================================================
29
30 create table cvterm (
31        cvterm_id serial not null,
32        primary key (cvterm_id),
33        cv_id int not null,
34        foreign key (cv_id) references cv (cv_id),
35        name varchar(255) not null,
36        termdefinition text,
37        dbxref_id int,
38        foreign key (dbxref_id) references dbxref (dbxref_id),
39
40        unique(termname, cv_id)
41 );
42 create index cvterm_idx1 on cvterm (cv_id);
43 -- the primary dbxref for this term.  Other dbxrefs may be cvterm_dbxref
44 -- The unique key on termname, termtype_id ensures that all terms are 
45 -- unique within a given cv
46
47
48 -- ================================================
49 -- TABLE: cvrelationship
50 -- ================================================
51
52 create table cvrelationship (
53        cvrelationship_id serial not null,
54        primary key (cvrelationship_id),
55        reltype_id int not null,
56        foreign key (reltype_id) references cvterm (cvterm_id),
57        subjterm_id int not null,
58        foreign key (subjterm_id) references cvterm (cvterm_id),
59        objterm_id int not null,
60        foreign key (objterm_id) references cvterm (cvterm_id),
61
62        unique(reltype_id, subjterm_id, objterm_id)
63 );
64 create index cvrelationship_idx1 on cvrelationship (reltype_id);
65 create index cvrelationship_idx2 on cvrelationship (subjterm_id);
66 create index cvrelationship_idx3 on cvrelationship (objterm_id);
67
68
69 -- ================================================
70 -- TABLE: cvpath
71 -- ================================================
72
73 create table cvpath (
74        cvpath_id serial not null,
75        primary key (cvpath_id),
76        reltype_id int,
77        foreign key (reltype_id) references cvterm (cvterm_id),
78        subjterm_id int not null,
79        foreign key (subjterm_id) references cvterm (cvterm_id),
80        objterm_id int not null,
81        foreign key (objterm_id) references cvterm (cvterm_id),
82        cv_id int not null,
83        foreign key (cv_id) references cv (cv_id),
84        pathdistance int,
85
86        unique (subjterm_id, objterm_id)
87 );
88 create index cvpath_idx1 on cvpath (reltype_id);
89 create index cvpath_idx2 on cvpath (subjterm_id);
90 create index cvpath_idx3 on cvpath (objterm_id);
91 create index cvpath_idx4 on cvpath (cv_id);
92
93
94 -- ================================================
95 -- TABLE: cvtermsynonym
96 -- ================================================
97
98 create table cvtermsynonym (
99        cvterm_id int not null,
100        foreign key (cvterm_id) references cvterm (cvterm_id),
101        termsynonym varchar(255) not null,
102
103        unique(cvterm_id, termsynonym)
104 );
105 create index cvterm_synonym_idx1 on cvterm_synonym (cvterm_id);
106
107 -- ================================================
108 -- TABLE: cvterm_dbxref
109 -- ================================================
110
111 create table cvterm_dbxref (
112        cvterm_dbxref_id serial not null,
113        primary key (cvterm_dbxref_id),
114        cvterm_id int not null,
115        foreign key (cvterm_id) references cvterm (cvterm_id),
116        dbxref_id int not null,
117        foreign key (dbxref_id) references dbxref (dbxref_id),
118
119        unique(cvterm_id, dbxref_id)
120 );
121 create index cvterm_dbxref_idx1 on cvterm_dbxref (cvterm_id);
122 create index cvterm_dbxref_idx2 on cvterm_dbxref (dbxref_id);
123
124 |;
125
126 my $tr = SQL::Translator->new(
127     parser   => "PostgreSQL",
128     producer => "MySQL"
129 );
130
131 ok( $tr->translate(\$create), 'Translate PG2My' );