From: Allen Day Date: Tue, 25 Feb 2003 01:01:30 +0000 (+0000) Subject: added a serial->int auto_increment fix, a varchar->varchar(255) workaround. X-Git-Tag: v0.01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ba1a16260e2b07b9a7a230c3a1975e75690ef89a;p=dbsrgits%2FSQL-Translator.git added a serial->int auto_increment fix, a varchar->varchar(255) workaround. --- diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index be79cc0..5feb523 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -1,7 +1,7 @@ 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 , # darren chamberlain , @@ -42,7 +42,7 @@ The grammar is influenced heavily by Tim Bunce's "mysql2ora" grammar. 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; @@ -73,7 +73,7 @@ statement : comment 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; @@ -184,7 +184,7 @@ field_qualifier : ',' foreign_key '(' field_name ')' foreign_key_reference forei foreign_table => $item{'foreign_table_name'}, foreign_field => $item{'foreign_field_name'}, name => $item{'field_name'}, - } + } } field_qualifier : unsigned @@ -212,10 +212,14 @@ index_name : WORD 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]; } @@ -224,6 +228,8 @@ data_type : WORD parens_value_list(s?) type_qualifier(s?) $list = []; } + if(uc($type) =~ /^VARCHAR$/ and not defined($size)){ $size = [255] } + $return = { type => $type, size => $size, @@ -261,7 +267,7 @@ default_val : /default/i /(?:')?[\w\d.-]*(?:')?/ $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 } diff --git a/t/08postgres-to-mysql.t b/t/08postgres-to-mysql.t index 23d8232..22849fa 100644 --- a/t/08postgres-to-mysql.t +++ b/t/08postgres-to-mysql.t @@ -31,17 +31,94 @@ create table cvterm ( 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; @@ -173,3 +250,4 @@ create table cvterm_dbxref ( create index cvterm_dbxref_idx1 on cvterm_dbxref (cvterm_id); create index cvterm_dbxref_idx2 on cvterm_dbxref (dbxref_id); +