package SQL::Translator::Parser::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.1 2003-02-21 19:35:17 allenday Exp $
+# $Id: PostgreSQL.pm,v 1.2 2003-02-25 01:01:29 allenday Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
drop : /drop/i WORD(s) ';'
-create : create_table table_name '(' comment(s?) create_definition(s /,/) ')' table_option(s?) ';'
+create : create_table table_name '(' create_definition(s /,/) ')' table_option(s?) ';'
{
my $table_name = $item{'table_name'};
$tables{ $table_name }{'order'} = ++$table_order;
foreign_table => $item{'foreign_table_name'},
foreign_field => $item{'foreign_field_name'},
name => $item{'field_name'},
- }
+ }
}
field_qualifier : unsigned
data_type : WORD parens_value_list(s?) type_qualifier(s?)
{
my $type = $item[1];
+
my $size; # field size, applicable only to non-set fields
my $list; # set list, applicable only to sets (duh)
- if ( uc($type) =~ /^(SET|ENUM)$/ ) {
+
+ if(uc($type) =~ /^SERIAL$/){
+ $type = 'int';
+ } elsif ( uc($type) =~ /^(SET|ENUM)$/ ) {
$size = undef;
$list = $item[2][0];
}
$list = [];
}
+ if(uc($type) =~ /^VARCHAR$/ and not defined($size)){ $size = [255] }
+
$return = {
type => $type,
size => $size,
$return = $item[2];
}
-auto_inc : /auto_increment/i { 1 }
+auto_inc : /auto_increment/i { 1 } #see data_type
primary_key : /primary/i /key/i { 1 }
foreign key (cv_id) references cv (cv_id),
name varchar(255) not null,
termdefinition text,
--- the primary dbxref for this term. Other dbxrefs may be cvterm_dbxref
dbxref_id int,
foreign key (dbxref_id) references dbxref (dbxref_id),
unique(termname, cv_id)
);
create index cvterm_idx1 on cvterm (cv_id);
+-- the primary dbxref for this term. Other dbxrefs may be cvterm_dbxref
+-- The unique key on termname, termtype_id ensures that all terms are
+-- unique within a given cv
+
+
+-- ================================================
+-- TABLE: cvrelationship
+-- ================================================
+
+create table cvrelationship (
+ cvrelationship_id serial not null,
+ primary key (cvrelationship_id),
+ reltype_id int not null,
+ foreign key (reltype_id) references cvterm (cvterm_id),
+ subjterm_id int not null,
+ foreign key (subjterm_id) references cvterm (cvterm_id),
+ objterm_id int not null,
+ foreign key (objterm_id) references cvterm (cvterm_id),
+
+ unique(reltype_id, subjterm_id, objterm_id)
+);
+create index cvrelationship_idx1 on cvrelationship (reltype_id);
+create index cvrelationship_idx2 on cvrelationship (subjterm_id);
+create index cvrelationship_idx3 on cvrelationship (objterm_id);
+
+
+-- ================================================
+-- TABLE: cvpath
+-- ================================================
+
+create table cvpath (
+ cvpath_id serial not null,
+ primary key (cvpath_id),
+ reltype_id int,
+ foreign key (reltype_id) references cvterm (cvterm_id),
+ subjterm_id int not null,
+ foreign key (subjterm_id) references cvterm (cvterm_id),
+ objterm_id int not null,
+ foreign key (objterm_id) references cvterm (cvterm_id),
+ cv_id int not null,
+ foreign key (cv_id) references cv (cv_id),
+ pathdistance int,
+
+ unique (subjterm_id, objterm_id)
+);
+create index cvpath_idx1 on cvpath (reltype_id);
+create index cvpath_idx2 on cvpath (subjterm_id);
+create index cvpath_idx3 on cvpath (objterm_id);
+create index cvpath_idx4 on cvpath (cv_id);
+
+
+-- ================================================
+-- TABLE: cvtermsynonym
+-- ================================================
+
+create table cvtermsynonym (
+ cvterm_id int not null,
+ foreign key (cvterm_id) references cvterm (cvterm_id),
+ termsynonym varchar(255) not null,
+
+ unique(cvterm_id, termsynonym)
+);
+create index cvterm_synonym_idx1 on cvterm_synonym (cvterm_id);
+
+-- ================================================
+-- TABLE: cvterm_dbxref
+-- ================================================
+
+create table cvterm_dbxref (
+ cvterm_dbxref_id serial not null,
+ primary key (cvterm_dbxref_id),
+ cvterm_id int not null,
+ foreign key (cvterm_id) references cvterm (cvterm_id),
+ dbxref_id int not null,
+ foreign key (dbxref_id) references dbxref (dbxref_id),
+
+ unique(cvterm_id, dbxref_id)
+);
+create index cvterm_dbxref_idx1 on cvterm_dbxref (cvterm_id);
+create index cvterm_dbxref_idx2 on cvterm_dbxref (dbxref_id);
|;
-#-- The unique key on termname, termtype_id ensures that all terms are
-#-- unique within a given cv
use SQL::Translator;
use Data::Dumper;
create index cvterm_dbxref_idx1 on cvterm_dbxref (cvterm_id);
create index cvterm_dbxref_idx2 on cvterm_dbxref (dbxref_id);
+