From d38bebf99064916053885424c8b1416b6b52a608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 2 Jul 2014 21:04:34 +0200 Subject: [PATCH 1/2] Created foreign key relations for llx_product and llx_product_price table --- .../install/mysql/migration/3.6.0-3.7.0.sql | 33 +++++++++++++++++++ .../install/mysql/tables/llx_product.key.sql | 17 +++++++++- htdocs/install/mysql/tables/llx_product.sql | 7 ++-- .../mysql/tables/llx_product_price.key.sql | 28 ++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_product_price.key.sql diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index a8019d3af4c..2b98536fa95 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -49,3 +49,36 @@ ALTER TABLE llx_user MODIFY COLUMN accountancy_code varchar(32); ALTER TABLE llx_bank_account ADD COLUMN accountancy_journal varchar(3) DEFAULT NULL AFTER account_number; + +-- Added missing relations of llx_product +-- fk_country +ALTER TABLE llx_product CHANGE fk_country fk_country INT( 11 ) NULL DEFAULT NULL; +ALTER TABLE llx_product ADD INDEX ( fk_country ); +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_country ) REFERENCES llx_c_pays ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; +-- fk_user_author +ALTER TABLE llx_product CHANGE fk_user_author fk_user_author INT( 11 ) NULL DEFAULT NULL; +ALTER TABLE llx_product ADD INDEX ( fk_user_author ); +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; +-- fk_barcode_type +ALTER TABLE llx_product CHANGE fk_barcode_type fk_barcode_type INT( 11 ) NULL DEFAULT NULL; +UPDATE llx_product SET fk_barcode_type = NULL WHERE fk_barcode_type = 0; +ALTER TABLE llx_product ADD INDEX ( fk_barcode_type ); +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_barcode_type ) REFERENCES llx_c_barcode_type ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; + +-- Added missing relations of llx_product_price +-- fk_user_author +ALTER TABLE llx_product_price ADD INDEX ( fk_user_author ); +ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( + rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; +-- fk_user_author +ALTER TABLE llx_product_price ADD INDEX ( fk_product ); +ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_product ) REFERENCES llx_product ( + rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_product.key.sql b/htdocs/install/mysql/tables/llx_product.key.sql index a2cb0e539f9..4faa2bcb13c 100644 --- a/htdocs/install/mysql/tables/llx_product.key.sql +++ b/htdocs/install/mysql/tables/llx_product.key.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2002-2004 Rodolphe Quiedeville -- Copyright (C) 2004-2013 Laurent Destailleur -- Copyright (C) 2005-2009 Regis Houssin +-- Copyright (C) 2014 Marcos García -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -25,6 +26,20 @@ ALTER TABLE llx_product ADD INDEX idx_product_label (label); ALTER TABLE llx_product ADD INDEX idx_product_barcode (barcode); ALTER TABLE llx_product ADD INDEX idx_product_import_key (import_key); ALTER TABLE llx_product ADD INDEX idx_product_seuil_stock_alerte (seuil_stock_alerte); - +ALTER TABLE llx_product ADD INDEX ( fk_country ); +ALTER TABLE llx_product ADD INDEX ( fk_user_author ); +ALTER TABLE llx_product ADD INDEX ( fk_barcode_type ); ALTER TABLE llx_product ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity); + +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_country ) REFERENCES llx_c_pays ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; + +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; + +ALTER TABLE llx_product ADD FOREIGN KEY ( fk_barcode_type ) REFERENCES llx_c_barcode_type ( +rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 0ff94c19530..0ab9a24785c 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -4,6 +4,7 @@ -- Copyright (C) 2005-2010 Regis Houssin -- Copyright (C) 2010 juanjo Menent -- Copyright (C) 2013 Cédric Salvador +-- Copyright (C) 2014 Marcos García -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -37,7 +38,7 @@ create table llx_product description text, note text, customcode varchar(32), -- Optionnal custom code - fk_country integer, -- Optionnal id of original country + fk_country integer DEFAULT NULL, -- Optionnal id of original country price double(24,8) DEFAULT 0, price_ttc double(24,8) DEFAULT 0, price_min double(24,8) DEFAULT 0, @@ -47,7 +48,7 @@ create table llx_product recuperableonly integer NOT NULL DEFAULT '0', -- French NPR VAT localtax1_tx double(6,3) DEFAULT 0, -- Spanish local VAT 1 localtax2_tx double(6,3) DEFAULT 0, -- Spanish local VAT 2 - fk_user_author integer, + fk_user_author integer DEFAULT NULL, tosell tinyint DEFAULT 1, -- Product you sell tobuy tinyint DEFAULT 1, -- Product you buy tobatch tinyint DEFAULT 0 NOT NULL, -- Is it a product that need a batch or eat-by management @@ -56,7 +57,7 @@ create table llx_product seuil_stock_alerte integer DEFAULT 0, url varchar(255), barcode varchar(255) DEFAULT NULL, - fk_barcode_type integer DEFAULT 0, + fk_barcode_type integer DEFAULT NULL, accountancy_code_sell varchar(32), -- Selling accountancy code accountancy_code_buy varchar(32), -- Buying accountancy code partnumber varchar(32), -- Not used. Used by external modules. diff --git a/htdocs/install/mysql/tables/llx_product_price.key.sql b/htdocs/install/mysql/tables/llx_product_price.key.sql new file mode 100644 index 00000000000..a7e43d95d86 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_product_price.key.sql @@ -0,0 +1,28 @@ +-- ============================================================================ +-- Copyright (C) 2014 Marcos García +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ============================================================================ + +ALTER TABLE llx_product_price ADD INDEX ( fk_user_author ); +ALTER TABLE llx_product_price ADD INDEX ( fk_product ); + +ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_product ) REFERENCES llx_product ( + rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; + +ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( + rowid +) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file From e351657cc08d111e13680d971ab2425d3e4c4ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Thu, 3 Jul 2014 10:16:37 +0200 Subject: [PATCH 2/2] Removed key restrictions --- htdocs/install/mysql/migration/3.6.0-3.7.0.sql | 10 +++++----- htdocs/install/mysql/tables/llx_product.key.sql | 6 +++--- htdocs/install/mysql/tables/llx_product_price.key.sql | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 2b98536fa95..1a9c59b6275 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -56,29 +56,29 @@ ALTER TABLE llx_product CHANGE fk_country fk_country INT( 11 ) NULL DEFAULT N ALTER TABLE llx_product ADD INDEX ( fk_country ); ALTER TABLE llx_product ADD FOREIGN KEY ( fk_country ) REFERENCES llx_c_pays ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); -- fk_user_author ALTER TABLE llx_product CHANGE fk_user_author fk_user_author INT( 11 ) NULL DEFAULT NULL; ALTER TABLE llx_product ADD INDEX ( fk_user_author ); ALTER TABLE llx_product ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); -- fk_barcode_type ALTER TABLE llx_product CHANGE fk_barcode_type fk_barcode_type INT( 11 ) NULL DEFAULT NULL; UPDATE llx_product SET fk_barcode_type = NULL WHERE fk_barcode_type = 0; ALTER TABLE llx_product ADD INDEX ( fk_barcode_type ); ALTER TABLE llx_product ADD FOREIGN KEY ( fk_barcode_type ) REFERENCES llx_c_barcode_type ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); -- Added missing relations of llx_product_price -- fk_user_author ALTER TABLE llx_product_price ADD INDEX ( fk_user_author ); ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); -- fk_user_author ALTER TABLE llx_product_price ADD INDEX ( fk_product ); ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_product ) REFERENCES llx_product ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file +); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_product.key.sql b/htdocs/install/mysql/tables/llx_product.key.sql index 4faa2bcb13c..b692a2740b0 100644 --- a/htdocs/install/mysql/tables/llx_product.key.sql +++ b/htdocs/install/mysql/tables/llx_product.key.sql @@ -34,12 +34,12 @@ ALTER TABLE llx_product ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode ALTER TABLE llx_product ADD FOREIGN KEY ( fk_country ) REFERENCES llx_c_pays ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); ALTER TABLE llx_product ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); ALTER TABLE llx_product ADD FOREIGN KEY ( fk_barcode_type ) REFERENCES llx_c_barcode_type ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file +); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_product_price.key.sql b/htdocs/install/mysql/tables/llx_product_price.key.sql index a7e43d95d86..fbc5ee3f05f 100644 --- a/htdocs/install/mysql/tables/llx_product_price.key.sql +++ b/htdocs/install/mysql/tables/llx_product_price.key.sql @@ -21,8 +21,8 @@ ALTER TABLE llx_product_price ADD INDEX ( fk_product ); ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_product ) REFERENCES llx_product ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; +); ALTER TABLE llx_product_price ADD FOREIGN KEY ( fk_user_author ) REFERENCES llx_user ( rowid -) ON DELETE RESTRICT ON UPDATE RESTRICT ; \ No newline at end of file +); \ No newline at end of file