Fix: Gestion du double et gestion des ordres mysql "UNIQUE INDEX" et "INDEX"
This commit is contained in:
parent
459ffbdc46
commit
4bf603c113
@ -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<length($enum)) { $maxlength=length($enum); }
|
||||
}
|
||||
$_ = qq~ $1 CHAR($maxlength) CHECK ($1 IN ($2)) $3\n~;
|
||||
} elsif (/^[\s\t]*(\w*)\s*.*int.*auto_increment/i) { # int,auto_increment -> 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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user