Skip to content

Commit

Permalink
Created foreign key relations for llx_product and llx_product_price t…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
marcosgdf committed Jul 2, 2014
1 parent 61ff1d2 commit d38bebf
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
33 changes: 33 additions & 0 deletions htdocs/install/mysql/migration/3.6.0-3.7.0.sql
Expand Up @@ -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 ;
17 changes: 16 additions & 1 deletion htdocs/install/mysql/tables/llx_product.key.sql
Expand Up @@ -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
Expand All @@ -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 ;
7 changes: 4 additions & 3 deletions htdocs/install/mysql/tables/llx_product.sql
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions 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 ;

1 comment on commit d38bebf

@eldy
Copy link
Member

@eldy eldy commented on d38bebf Jul 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the on delete and on restrict. Any change on database content must be done by php code to support correctly trigger, hooks, or be sure code report child depencie confirmation forms ?

Please sign in to comment.