Browse Source

Created foreign key relations for llx_product and llx_product_price table

Marcos García de La Fuente 11 years ago
parent
commit
d38bebf990

+ 33 - 0
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 ;

+ 16 - 1
htdocs/install/mysql/tables/llx_product.key.sql

@@ -2,6 +2,7 @@
 -- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
 -- Copyright (C) 2004-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
 -- Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@capnetworks.com>
+-- Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
 --
 -- 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 ;

+ 4 - 3
htdocs/install/mysql/tables/llx_product.sql

@@ -4,6 +4,7 @@
 -- Copyright (C) 2005-2010 Regis Houssin        <regis.houssin@capnetworks.com>
 -- Copyright (C) 2010      juanjo Menent        <jmenent@2byte.es>
 -- Copyright (C) 2013      Cédric Salvador      <csalvador@gpcsolutions.fr>
+-- Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
 --
 -- 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.

+ 28 - 0
htdocs/install/mysql/tables/llx_product_price.key.sql

@@ -0,0 +1,28 @@
+-- ============================================================================
+-- Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
+--
+-- 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 <http://www.gnu.org/licenses/>.
+--
+-- ============================================================================
+
+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 ;