From 807670710915638b43125883cb3673c06ec7f703 Mon Sep 17 00:00:00 2001 From: davidd Date: Fri, 23 Feb 2024 13:29:36 +0100 Subject: [PATCH 1/3] refs #6372 --- .../10896-salmonOrchid/03-gastos_resumen.sql | 28 ++++++++++++------- .../10896-salmonOrchid/14-movement_label.sql | 4 +++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index dbb71bca2..19dc4cbbd 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -1,24 +1,32 @@ -ALTER TABLE IF EXISTS vn2008.gastos_resumen DROP FOREIGN KEY IF EXISTS gastos_resumen_expense_FK; -ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseManual`; +DELETE FROM vn2008.gastos_resumen + WHERE Id_Gasto IN ( + SELECT DISTINCT g.Id_Gasto + FROM vn2008.gastos_resumen g + LEFT JOIN expense e ON e.id = g.Id_Gasto COLLATE utf8mb3_general_ci + WHERE e.id IS NULL + ); -ALTER TABLE IF EXISTS `vn`.`expenseManual` +ALTER TABLE `vn2008`.`gastos_resumen` DROP FOREIGN KEY gastos_resumen_expense_FK; +ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseManual`; +ALTER TABLE `vn`.`expenseManual` CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; -ALTER TABLE IF EXISTS vn.expenseManual COLLATE=utf8mb3_general_ci; +ALTER TABLE vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; -ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; - -ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; +ALTER TABLE vn.expenseManual DROP PRIMARY KEY; ALTER TABLE vn.expenseManual MODIFY COLUMN companyFk int(10) unsigned NULL; +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; + UPDATE vn.expenseManual SET companyFK= NULL WHERE companyFk= 0; -ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.expenseManual ADD COLUMN id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST; + +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_unique UNIQUE KEY IF NOT EXISTS (expenseFk,`year`,`month`,companyFk); \ No newline at end of file diff --git a/db/versions/10896-salmonOrchid/14-movement_label.sql b/db/versions/10896-salmonOrchid/14-movement_label.sql index a3ccf320d..40e4d302b 100644 --- a/db/versions/10896-salmonOrchid/14-movement_label.sql +++ b/db/versions/10896-salmonOrchid/14-movement_label.sql @@ -1,8 +1,12 @@ DROP TRIGGER IF EXISTS `vn2008`.`movement_label_afterUpdate`; +ALTER TABLE vn2008.movement_label DROP FOREIGN KEY movement_label_ibfk_1; + DROP VIEW IF EXISTS `vn`.`saleLabel`; ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`saleLabel`; ALTER TABLE IF EXISTS `vn`.`saleLabel` CHANGE COLUMN IF EXISTS `Id_movimiento` `saleFk` int(11) NOT NULL; + +ALTER TABLE vn.saleLabel ADD CONSTRAINT saleLabel_sale_FK FOREIGN KEY (saleFk) REFERENCES vn.sale(id) ON DELETE CASCADE ON UPDATE CASCADE; From d62c7ef0f53de0a93bb8b039405dcb8b9d352bfd Mon Sep 17 00:00:00 2001 From: davidd Date: Fri, 23 Feb 2024 13:45:48 +0100 Subject: [PATCH 2/3] refs #6372 --- .../10896-salmonOrchid/03-gastos_resumen.sql | 16 ++++++++-------- .../10896-salmonOrchid/14-movement_label.sql | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index 19dc4cbbd..4da8148e0 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -13,20 +13,20 @@ CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; -ALTER TABLE vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; +ALTER TABLE `vn`.`expenseManual` MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; -ALTER TABLE vn.expenseManual DROP PRIMARY KEY; +ALTER TABLE `vn`.`expenseManual` DROP PRIMARY KEY; -ALTER TABLE vn.expenseManual MODIFY COLUMN companyFk int(10) unsigned NULL; +ALTER TABLE `vn`.`expenseManual` MODIFY COLUMN companyFk int(10) unsigned NULL; -ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; -UPDATE vn.expenseManual +UPDATE `vn`.`expenseManual` SET companyFK= NULL WHERE companyFk= 0; -ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE vn.expenseManual ADD COLUMN id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST; +ALTER TABLE `vn`.`expenseManual` ADD COLUMN id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST; -ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_unique UNIQUE KEY IF NOT EXISTS (expenseFk,`year`,`month`,companyFk); \ No newline at end of file +ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_unique UNIQUE KEY IF NOT EXISTS (expenseFk,`year`,`month`,companyFk); \ No newline at end of file diff --git a/db/versions/10896-salmonOrchid/14-movement_label.sql b/db/versions/10896-salmonOrchid/14-movement_label.sql index 40e4d302b..194df6e1e 100644 --- a/db/versions/10896-salmonOrchid/14-movement_label.sql +++ b/db/versions/10896-salmonOrchid/14-movement_label.sql @@ -9,4 +9,4 @@ ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`saleLabel`; ALTER TABLE IF EXISTS `vn`.`saleLabel` CHANGE COLUMN IF EXISTS `Id_movimiento` `saleFk` int(11) NOT NULL; -ALTER TABLE vn.saleLabel ADD CONSTRAINT saleLabel_sale_FK FOREIGN KEY (saleFk) REFERENCES vn.sale(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `vn`.`saleLabel` ADD CONSTRAINT saleLabel_sale_FK FOREIGN KEY (saleFk) REFERENCES vn.sale(id) ON DELETE CASCADE ON UPDATE CASCADE; From e971070f2f8e98d500871fb4604cac770077ab72 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 23 Feb 2024 14:21:40 +0100 Subject: [PATCH 3/3] fix: refs #6372 Version --- db/versions/10896-salmonOrchid/03-gastos_resumen.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index 4da8148e0..1f5101df5 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -2,7 +2,7 @@ DELETE FROM vn2008.gastos_resumen WHERE Id_Gasto IN ( SELECT DISTINCT g.Id_Gasto FROM vn2008.gastos_resumen g - LEFT JOIN expense e ON e.id = g.Id_Gasto COLLATE utf8mb3_general_ci + LEFT JOIN vn.expense e ON e.id = g.Id_Gasto COLLATE utf8mb3_general_ci WHERE e.id IS NULL );