diff --git a/build/dolibarr_mysql2pgsql.pl b/build/dolibarr_mysql2pgsql.pl index 3ba5016cc7b..35c0658e34b 100644 --- a/build/dolibarr_mysql2pgsql.pl +++ b/build/dolibarr_mysql2pgsql.pl @@ -111,7 +111,11 @@ foreach my $file (keys %filelist) { print OUT "-- (c) 2005, Laurent Destailleur.\n"; print OUT "\n"; + # Output for create table and create index sub output_create { + # If command ends with "xxx,);", we change to "xxx);" + $create_sql =~ s/,(\s*)\)/$1\)/m; + print OUT $create_sql; if ($create_index) { print OUT "\n"; @@ -119,7 +123,7 @@ foreach my $file (keys %filelist) { } } - # reset when moving from each "create table" to "insert" part of dump + # Reset when moving from each "create table" to "insert" part of dump sub reset_vars() { $create_sql=""; $create_index=""; @@ -142,13 +146,15 @@ foreach my $file (keys %filelist) { next; } if ($create_sql ne "") { # we are inside create table statement so lets process datatypes + if (/\);/i) { # end of create table squence $create_sql =~ s/,$//g; # strip last , inside create table &output_create; &reset_vars(); next; # LDR Added innodb - } elsif (/(ISAM|innodb)/i) { # end of create table sequence + } + elsif (/(ISAM|innodb)/i) { # end of create table sequence s/\) *Type=(MyISAM|innodb);/);/i; $create_sql =~ s/,$//g; # strip last , inside create table $create_sql .= $_; @@ -157,16 +163,20 @@ foreach my $file (keys %filelist) { next; } + # enum -> check if (/(\w*)\s+enum\(((?:['"]\w+['"]\s*,)+['"]\w+['"])\)(.*)$/i) { # enum handling $enum_column=$1; - $enum_datafield{$enum_column} = $2; # 'abc','def', ... + $enum_datafield{$enum_column}=$2; # 'abc','def', ... + my $suite=$3; my $maxlength=0; - foreach my $enum (split(',',$2)) { + foreach my $enum (split(',',$enum_datafield{$enum_column})) { $enum =~ s/[\"\']//g; if ($maxlength serial + $enum_datafield{$enum_column} =~ s/\"/\'/g; + $_ = qq~ $enum_column CHAR($maxlength) CHECK ($enum_column IN ($enum_datafield{$enum_column})) $suite\n~; + # int, auto_increment -> serial + } elsif (/^[\s\t]*(\w*)\s*.*int.*auto_increment/i) { $seq = qq~${table}_${1}_seq~; s/[\s\t]*([a-zA-Z_0-9]*)\s*.*int.*auto_increment[^,]*/ $1 SERIAL PRIMARY KEY/ig; # MYSQL: data_id mediumint(8) unsigned NOT NULL auto_increment, @@ -185,6 +195,7 @@ foreach my $file (keys %filelist) { } s/\w*int\(\d+\)/$out/g; } + # tinyint -> smallint elsif (/tinyint/i) { s/tinyint/smallint/g; } @@ -218,19 +229,31 @@ foreach my $file (keys %filelist) { # nuke size of timestamp s/timestamp\([^)]*\)/timestamp/i; - # double -> float8 - s/double\([^)]*\)/float8/i; + # double -> real + s/^double/real/i; + s/(\s*)double/${1}real/i; - # FIX: unique for multipe columns (col1,col2) are unsupported! - # Ignore "unique key(xx, yy)" + # Ignore "unique key(xx, yy)" (key on double fields not supported by postgres) next if (/unique key\(\w+\s*,\s*\w+\)/i); if (/\bkey\b/i && !/^\s+primary key\s+/i) { s/KEY(\s+)[^(]*(\s+)/$1 UNIQUE $2/i; # hack off name of the non-primary key } - # if key(xxx) - if (/key\((\w+)\)/i) { + # unique index(field) + if (/unique index\s*(\w*)\s*\((\w+)\)/i) { + $create_index .= "CREATE INDEX ".($1?"$1":"idx_$2")." ON $table ($2);\n"; + next; + } + + # index(field) + if (/index\s*(\w*)\s*\((\w+)\)/i) { + $create_index .= "CREATE INDEX ".($1?"$1":"idx_$2")." ON $table ($2);\n"; + next; + } + + # key(xxx) + if (/key\s*\((\w+)\)/i) { #$create_index .= "CREATE INDEX ${table}_$1 ON $table ($1);\n"; $create_index .= "CREATE INDEX idx_$1 ON $table ($1);\n"; next; diff --git a/pgsql/tables/llx_adherent.sql b/pgsql/tables/llx_adherent.sql index 9d2bff16062..5664ba9267b 100644 --- a/pgsql/tables/llx_adherent.sql +++ b/pgsql/tables/llx_adherent.sql @@ -55,7 +55,8 @@ create table llx_adherent "fk_user_mod" integer NOT NULL, "fk_user_valid" integer NOT NULL, "datefin" timestamp, -- date de fin de validité de la cotisation - "note" text, + "note" text - "UNIQUE" INDEX(login) ); + +CREATE INDEX idx_login ON llx_adherent (login); diff --git a/pgsql/tables/llx_adherent_options.sql b/pgsql/tables/llx_adherent_options.sql index 7ca8f88eabf..a440e47605a 100644 --- a/pgsql/tables/llx_adherent_options.sql +++ b/pgsql/tables/llx_adherent_options.sql @@ -33,5 +33,6 @@ create table llx_adherent_options optid SERIAL PRIMARY KEY, "tms" timestamp, "adhid" integer NOT NULL, -- id de l'adherent auquel correspond ces attributs optionnel - "UNIQUE" INDEX(adhid) ); + +CREATE INDEX idx_adhid ON llx_adherent_options (adhid); diff --git a/pgsql/tables/llx_bank_class.sql b/pgsql/tables/llx_bank_class.sql index b34c703facc..c6804e8995b 100644 --- a/pgsql/tables/llx_bank_class.sql +++ b/pgsql/tables/llx_bank_class.sql @@ -26,6 +26,7 @@ create table llx_bank_class ( "lineid" integer NOT NULL, - "fk_categ" integer NOT NULL, - "INDEX"(lineid) + "fk_categ" integer NOT NULL ); + +CREATE INDEX idx_lineid ON llx_bank_class (lineid); diff --git a/pgsql/tables/llx_bookmark4u_login.sql b/pgsql/tables/llx_bookmark4u_login.sql index 18edf9e6428..636a92b290f 100644 --- a/pgsql/tables/llx_bookmark4u_login.sql +++ b/pgsql/tables/llx_bookmark4u_login.sql @@ -29,6 +29,7 @@ create table llx_bookmark4u_login ( rowid SERIAL PRIMARY KEY, "fk_user" integer, - "bk4u_uid" integer, - "UNIQUE" INDEX(fk_user) + "bk4u_uid" integer ); + +CREATE INDEX idx_fk_user ON llx_bookmark4u_login (fk_user); diff --git a/pgsql/tables/llx_c_departements.sql b/pgsql/tables/llx_c_departements.sql index 2d587be7536..eb5f443dbeb 100644 --- a/pgsql/tables/llx_c_departements.sql +++ b/pgsql/tables/llx_c_departements.sql @@ -35,9 +35,10 @@ create table llx_c_departements "tncc" integer, "ncc" varchar(50), "nom" varchar(50), - "active" smallint DEFAULT 1 NOT NULL, - key (fk_region) + "active" smallint DEFAULT 1 NOT NULL ); +CREATE INDEX idx_fk_region ON llx_c_departements (fk_region); + diff --git a/pgsql/tables/llx_commande.sql b/pgsql/tables/llx_commande.sql index 3487dc54412..93c4d65ca55 100644 --- a/pgsql/tables/llx_commande.sql +++ b/pgsql/tables/llx_commande.sql @@ -49,6 +49,7 @@ create table llx_commande "total_ttc" real default 0, "note" text, "model_pdf" varchar(50), - "facture" smallint default 0, - "UNIQUE" INDEX (ref) + "facture" smallint default 0 ); + +CREATE INDEX idx_ref ON llx_commande (ref); diff --git a/pgsql/tables/llx_commande_fournisseur.sql b/pgsql/tables/llx_commande_fournisseur.sql index 85d1cefc42f..382bd52c672 100644 --- a/pgsql/tables/llx_commande_fournisseur.sql +++ b/pgsql/tables/llx_commande_fournisseur.sql @@ -50,6 +50,7 @@ create table llx_commande_fournisseur "total_ht" real default 0, "total_ttc" real default 0, "note" text, - "model_pdf" varchar(50), - "UNIQUE" INDEX (ref) + "model_pdf" varchar(50) ); + +CREATE INDEX idx_ref ON llx_commande_fournisseur (ref); diff --git a/pgsql/tables/llx_const.sql b/pgsql/tables/llx_const.sql index 8418d3352e2..fa2e0f1a6ab 100644 --- a/pgsql/tables/llx_const.sql +++ b/pgsql/tables/llx_const.sql @@ -36,6 +36,7 @@ create table llx_const "value" text, -- max 65535 caracteres "type" varchar(6) CHECK (type IN ('yesno','texte','chaine')) , "visible" smallint DEFAULT 1 NOT NULL, - "note" text, - "UNIQUE" INDEX(name) + "note" text ); + +CREATE INDEX idx_name ON llx_const (name); diff --git a/pgsql/tables/llx_expedition.sql b/pgsql/tables/llx_expedition.sql index e13263e2d80..c07a7d7fe46 100644 --- a/pgsql/tables/llx_expedition.sql +++ b/pgsql/tables/llx_expedition.sql @@ -40,9 +40,9 @@ create table llx_expedition "fk_expedition_methode" integer, "fk_statut" smallint DEFAULT 0, "note" text, - "model_pdf" varchar(50), - "UNIQUE" INDEX (ref) + "model_pdf" varchar(50) ); +CREATE INDEX idx_ref ON llx_expedition (ref); CREATE INDEX idx_fk_expedition_methode ON llx_expedition (fk_expedition_methode); CREATE INDEX idx_fk_commande ON llx_expedition (fk_commande); diff --git a/pgsql/tables/llx_facture.sql b/pgsql/tables/llx_facture.sql index bae2f9aff07..c56f422ff15 100644 --- a/pgsql/tables/llx_facture.sql +++ b/pgsql/tables/llx_facture.sql @@ -48,7 +48,8 @@ create table llx_facture "fk_cond_reglement" integer, -- condition de reglement (30 jours, fin de mois ...) "fk_mode_reglement" integer, -- mode de reglement (Virement, Prélèvement) "date_lim_reglement" date, -- date limite de reglement - "note" text, - "UNIQUE" INDEX (facnumber), - "INDEX" fksoc (fk_soc) + "note" text ); + +CREATE INDEX idx_facnumber ON llx_facture (facnumber); +CREATE INDEX fksoc ON llx_facture (fk_soc); diff --git a/pgsql/tables/llx_facture_rec.sql b/pgsql/tables/llx_facture_rec.sql index 7046795868e..0821b02a995 100644 --- a/pgsql/tables/llx_facture_rec.sql +++ b/pgsql/tables/llx_facture_rec.sql @@ -42,6 +42,7 @@ create table llx_facture_rec "fk_user_author" integer, -- createur "fk_projet" integer, -- projet auquel est associé la facture "fk_cond_reglement" integer, -- condition de reglement - "note" text, - "INDEX" fksoc (fk_soc) + "note" text ); + +CREATE INDEX fksoc ON llx_facture_rec (fk_soc); diff --git a/pgsql/tables/llx_fichinter.sql b/pgsql/tables/llx_fichinter.sql index e6a57e9b940..d4824d9648b 100644 --- a/pgsql/tables/llx_fichinter.sql +++ b/pgsql/tables/llx_fichinter.sql @@ -38,6 +38,7 @@ create table llx_fichinter "fk_user_valid" integer, -- valideur de la fiche "fk_statut" smallint DEFAULT 0, "duree" real, - "note" text, - "UNIQUE" INDEX (ref) + "note" text ); + +CREATE INDEX idx_ref ON llx_fichinter (ref); diff --git a/pgsql/tables/llx_groupart.sql b/pgsql/tables/llx_groupart.sql index 34e3f0f26d2..43d2a3f1dd8 100644 --- a/pgsql/tables/llx_groupart.sql +++ b/pgsql/tables/llx_groupart.sql @@ -30,7 +30,7 @@ create table llx_groupart "osc_id" integer NOT NULL, "tms" timestamp, "nom" varchar(64), - "groupart" varchar(7) CHECK (groupart IN ("artiste","groupe")) NOT NULL, + "groupart" varchar(7) CHECK (groupart IN ('artiste','groupe')) NOT NULL, "description" text NOT NULL, "fk_user_author" integer ); diff --git a/pgsql/tables/llx_paiement_facture.sql b/pgsql/tables/llx_paiement_facture.sql index 161d31c957f..a197790b6ec 100644 --- a/pgsql/tables/llx_paiement_facture.sql +++ b/pgsql/tables/llx_paiement_facture.sql @@ -29,8 +29,9 @@ create table llx_paiement_facture rowid SERIAL PRIMARY KEY, "fk_paiement" integer, "fk_facture" integer, - "amount" real DEFAULT 0, + "amount" real DEFAULT 0 - key (fk_paiement), - key (fk_facture) ); + +CREATE INDEX idx_fk_paiement ON llx_paiement_facture (fk_paiement); +CREATE INDEX idx_fk_facture ON llx_paiement_facture (fk_facture); diff --git a/pgsql/tables/llx_product.sql b/pgsql/tables/llx_product.sql index 2799763513f..41efd86f7b4 100644 --- a/pgsql/tables/llx_product.sql +++ b/pgsql/tables/llx_product.sql @@ -33,8 +33,8 @@ create table llx_product "ref" varchar(15) UNIQUE, "label" varchar(255), "description" text, - "price" double, - "tva_tx" double DEFAULT 19.6, + "price" real, + "tva_tx" real DEFAULT 19.6, "fk_user_author" integer, "envente" smallint DEFAULT 1, "nbvente" integer DEFAULT 0, diff --git a/pgsql/tables/llx_product_price.sql b/pgsql/tables/llx_product_price.sql index 8696878d371..98b01a28298 100644 --- a/pgsql/tables/llx_product_price.sql +++ b/pgsql/tables/llx_product_price.sql @@ -30,8 +30,8 @@ create table llx_product_price "tms" timestamp, "fk_product" integer NOT NULL, "date_price" timestamp, - "price" double, - "tva_tx" double DEFAULT 19.6, + "price" real, + "tva_tx" real DEFAULT 19.6, "fk_user_author" integer, "envente" smallint DEFAULT 1 ); diff --git a/pgsql/tables/llx_projet.sql b/pgsql/tables/llx_projet.sql index f049d99c131..1299cade4d6 100644 --- a/pgsql/tables/llx_projet.sql +++ b/pgsql/tables/llx_projet.sql @@ -37,6 +37,7 @@ create table llx_projet "title" varchar(255), "fk_user_resp" integer, -- responsable du projet "fk_user_creat" integer, -- createur du projet - "note" text, - "UNIQUE" INDEX(ref) + "note" text ); + +CREATE INDEX idx_ref ON llx_projet (ref); diff --git a/pgsql/tables/llx_propal.sql b/pgsql/tables/llx_propal.sql index 06907653c21..510ca104aa5 100644 --- a/pgsql/tables/llx_propal.sql +++ b/pgsql/tables/llx_propal.sql @@ -46,6 +46,7 @@ create table llx_propal "tva" real DEFAULT 0, "total" real DEFAULT 0, "note" text, - "model_pdf" varchar(50), - "UNIQUE" INDEX (ref) + "model_pdf" varchar(50) ); + +CREATE INDEX idx_ref ON llx_propal (ref); diff --git a/pgsql/tables/llx_societe.sql b/pgsql/tables/llx_societe.sql index 8e996072b0d..0115ea6d306 100644 --- a/pgsql/tables/llx_societe.sql +++ b/pgsql/tables/llx_societe.sql @@ -65,6 +65,7 @@ create table llx_societe "fk_user_creat" integer, -- utilisateur qui a créé l'info "fk_user_modif" integer, -- utilisateur qui a modifié l'info "remise_client" real DEFAULT 0, -- remise systématique pour le client - "UNIQUE" INDEX(prefix_comm) ); +CREATE INDEX idx_prefix_comm ON llx_societe (prefix_comm); + diff --git a/pgsql/tables/llx_user.sql b/pgsql/tables/llx_user.sql index 11fe57ed41e..26e985c421c 100644 --- a/pgsql/tables/llx_user.sql +++ b/pgsql/tables/llx_user.sql @@ -42,6 +42,7 @@ create table llx_user "module_compta" smallint DEFAULT 1, "fk_societe" integer DEFAULT 0, "fk_socpeople" integer DEFAULT 0, - "note" text, - "UNIQUE" INDEX(login) + "note" text ); + +CREATE INDEX idx_login ON llx_user (login);