diff --git a/build/dolibarr_mysql2pgsql.pl b/build/dolibarr_mysql2pgsql.pl index 35c0658e34b..202c08df597 100644 --- a/build/dolibarr_mysql2pgsql.pl +++ b/build/dolibarr_mysql2pgsql.pl @@ -114,7 +114,9 @@ foreach my $file (keys %filelist) { # 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; + $create_sql =~ s/,(\s*)\);/$1\);/m; + # If command ends with "xxx, -- yyy );", we change to "xxx -- yyy);" + $create_sql =~ s/,(\s*\-\-[^\)\n]*)(\s*)\);/$1\n\);/m; print OUT $create_sql; if ($create_index) { @@ -179,7 +181,6 @@ foreach my $file (keys %filelist) { } 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, $create_sql.=$_; next; # int type conversion @@ -200,8 +201,8 @@ foreach my $file (keys %filelist) { s/tinyint/smallint/g; } - # nuke int unsigned - s/(int\w+)\s+unsigned/$1/gi; + # nuke unsigned + s/(int\w+|smallint)\s+unsigned/$1/gi; # blob -> text @@ -234,7 +235,8 @@ foreach my $file (keys %filelist) { s/(\s*)double/${1}real/i; # Ignore "unique key(xx, yy)" (key on double fields not supported by postgres) - next if (/unique key\(\w+\s*,\s*\w+\)/i); + next if (/unique key\s*\(\w+\s*,\s*\w+\)/i); + next if (/unique index\s*\(\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 diff --git a/pgsql/tables/llx_adherent_options.sql b/pgsql/tables/llx_adherent_options.sql index a440e47605a..930713f6417 100644 --- a/pgsql/tables/llx_adherent_options.sql +++ b/pgsql/tables/llx_adherent_options.sql @@ -25,14 +25,12 @@ -- -- =================================================================== --- telfixe varchar(15), --- teljob varchar(15) create table llx_adherent_options ( optid SERIAL PRIMARY KEY, "tms" timestamp, - "adhid" integer NOT NULL, -- id de l'adherent auquel correspond ces attributs optionnel + "adhid" integer NOT NULL -- id de l'adherent auquel correspond ces attributs optionnel ); CREATE INDEX idx_adhid ON llx_adherent_options (adhid); diff --git a/pgsql/tables/llx_appro.sql b/pgsql/tables/llx_appro.sql index cd51f1d60d9..9d166328ec4 100644 --- a/pgsql/tables/llx_appro.sql +++ b/pgsql/tables/llx_appro.sql @@ -30,7 +30,7 @@ create table llx_appro "datec" timestamp, "tms" timestamp, "fk_product" integer NOT NULL, - "quantity" smallint unsigned NOT NULL, + "quantity" smallint NOT NULL, "price" real, "fk_user_author" integer ); diff --git a/pgsql/tables/llx_c_ape.sql b/pgsql/tables/llx_c_ape.sql index 11d9b4f4e9d..1aed38ea03b 100644 --- a/pgsql/tables/llx_c_ape.sql +++ b/pgsql/tables/llx_c_ape.sql @@ -25,11 +25,14 @@ -- -- ======================================================================== + create table llx_c_ape ( rowid SERIAL PRIMARY KEY, - code_ape varchar(5) PRIMARY KEY, + "code_ape" varchar(5) NOT NULL, "libelle" varchar(255), - "active" smallint DEFAULT 1 NOT NULL + "active" smallint DEFAULT 1 NOT NULL ); +CREATE INDEX idx_code_ape ON llx_c_ape (code_ape); + diff --git a/pgsql/tables/llx_contrat.key.sql b/pgsql/tables/llx_contrat.key.sql index f0fb7a94457..8bc3c3c89f5 100644 --- a/pgsql/tables/llx_contrat.key.sql +++ b/pgsql/tables/llx_contrat.key.sql @@ -28,12 +28,8 @@ -- -- ALTER TABLE llx_contrat ADD INDEX (fk_soc); -ALTER TABLE llx_contrat ADD INDEX (fk_commercial_signature); -ALTER TABLE llx_contrat ADD INDEX (fk_commercial_suivi); ALTER TABLE llx_contrat ADD INDEX (fk_user_author); -- -- ALTER TABLE llx_contrat ADD FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp); -ALTER TABLE llx_contrat ADD FOREIGN KEY (fk_commercial_signature) REFERENCES llx_user (rowid); -ALTER TABLE llx_contrat ADD FOREIGN KEY (fk_commercial_suivi) REFERENCES llx_user (rowid); ALTER TABLE llx_contrat ADD FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); diff --git a/pgsql/tables/llx_expeditiondet.sql b/pgsql/tables/llx_expeditiondet.sql index 034114bdfcd..6ed14125135 100644 --- a/pgsql/tables/llx_expeditiondet.sql +++ b/pgsql/tables/llx_expeditiondet.sql @@ -29,7 +29,7 @@ create table llx_expeditiondet rowid SERIAL PRIMARY KEY, "fk_expedition" integer NOT NULL, "fk_commande_ligne" integer NOT NULL, - "qty" real, -- quantité + "qty" real -- quantité ); CREATE INDEX idx_fk_expedition ON llx_expeditiondet (fk_expedition); diff --git a/pgsql/tables/llx_facture_fourn.sql b/pgsql/tables/llx_facture_fourn.sql index 3032210f290..23186c0116f 100644 --- a/pgsql/tables/llx_facture_fourn.sql +++ b/pgsql/tables/llx_facture_fourn.sql @@ -47,6 +47,5 @@ create table llx_facture_fourn "fk_statut" smallint DEFAULT 0 NOT NULL, "fk_user_author" integer, -- createur de la facture "fk_user_valid" integer, -- valideur de la facture - "note" text, - "UNIQUE" INDEX (facnumber, fk_soc) + "note" text ); diff --git a/pgsql/tables/llx_livre.sql b/pgsql/tables/llx_livre.sql index dd33518ae15..8aac4b5c6d2 100644 --- a/pgsql/tables/llx_livre.sql +++ b/pgsql/tables/llx_livre.sql @@ -39,7 +39,8 @@ create table llx_livre "prix" decimal(15,4), "fk_editeur" integer, "fk_user_author" integer, - "frais_de_port" smallint DEFAULT 1, - "UNIQUE"(ref) + "frais_de_port" smallint DEFAULT 1 ); +CREATE INDEX idx_ref ON llx_livre (ref); + diff --git a/pgsql/tables/llx_livre_to_auteur.sql b/pgsql/tables/llx_livre_to_auteur.sql index eea9351c077..8c61d96b32b 100644 --- a/pgsql/tables/llx_livre_to_auteur.sql +++ b/pgsql/tables/llx_livre_to_auteur.sql @@ -28,6 +28,5 @@ create table llx_livre_to_auteur ( "fk_livre" integer NOT NULL, - "fk_auteur" integer NOT NULL, - "unique" index (fk_livre, fk_auteur) + "fk_auteur" integer NOT NULL ); diff --git a/pgsql/tables/llx_prelevement.sql b/pgsql/tables/llx_prelevement.sql index 06292a08b01..cde4d3f090a 100644 --- a/pgsql/tables/llx_prelevement.sql +++ b/pgsql/tables/llx_prelevement.sql @@ -24,6 +24,8 @@ -- =================================================================== -- -- +-- N'est plus utilisé !! +-- create table llx_prelevement ( diff --git a/pgsql/tables/llx_product_stock.sql b/pgsql/tables/llx_product_stock.sql index 4328cfa5368..3f9c600d9d4 100644 --- a/pgsql/tables/llx_product_stock.sql +++ b/pgsql/tables/llx_product_stock.sql @@ -31,7 +31,7 @@ create table llx_product_stock "tms" timestamp, "fk_product" integer NOT NULL, "fk_entrepot" integer NOT NULL, - "reel" integer, -- stock réel + "reel" integer -- stock réel ); CREATE INDEX idx_fk_product ON llx_product_stock (fk_product); diff --git a/pgsql/tables/llx_societe.sql b/pgsql/tables/llx_societe.sql index 0115ea6d306..7de0d3bee99 100644 --- a/pgsql/tables/llx_societe.sql +++ b/pgsql/tables/llx_societe.sql @@ -64,7 +64,7 @@ create table llx_societe "rubrique" varchar(255), -- champ rubrique libre "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 + "remise_client" real DEFAULT 0 -- remise systématique pour le client ); CREATE INDEX idx_prefix_comm ON llx_societe (prefix_comm); diff --git a/pgsql/tables/llx_societe_commerciaux.sql b/pgsql/tables/llx_societe_commerciaux.sql index 992ea5bf32f..34395529776 100644 --- a/pgsql/tables/llx_societe_commerciaux.sql +++ b/pgsql/tables/llx_societe_commerciaux.sql @@ -29,7 +29,6 @@ create table llx_societe_commerciaux ( rowid SERIAL PRIMARY KEY, "fk_soc" integer, - "fk_user" integer, - "UNIQUE" INDEX(fk_soc, fk_user) + "fk_user" integer ); diff --git a/pgsql/tables/llx_user_rights.sql b/pgsql/tables/llx_user_rights.sql index a4b44cb7f0b..883714ad29a 100644 --- a/pgsql/tables/llx_user_rights.sql +++ b/pgsql/tables/llx_user_rights.sql @@ -29,7 +29,6 @@ create table llx_user_rights ( rowid SERIAL PRIMARY KEY, "fk_user" integer NOT NULL, - "fk_id" integer NOT NULL, - "UNIQUE"(fk_user,fk_id) + "fk_id" integer NOT NULL ); diff --git a/pgsql/tables/llx_usergroup_rights.key.sql b/pgsql/tables/llx_usergroup_rights.key.sql index 80172da61eb..0316eab8afe 100644 --- a/pgsql/tables/llx_usergroup_rights.key.sql +++ b/pgsql/tables/llx_usergroup_rights.key.sql @@ -25,6 +25,6 @@ -- =========================================================================== -- Supprimme orhpelins pour permettre montée de la clé -DELETE llx_usergroup_rights FROM llx_usergroup_rights LEFT JOIN llx_usergroup ON llx_usergroup_rights.fk_user = llx_usergroup.rowid WHERE llx_usergroup.rowid IS NULL; +DELETE llx_usergroup_rights FROM llx_usergroup_rights LEFT JOIN llx_usergroup ON llx_usergroup_rights.fk_usergroup = llx_usergroup.rowid WHERE llx_usergroup.rowid IS NULL; ALTER TABLE llx_usergroup_rights ADD FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid);