From d4b0da50d0a60cab3e1da5c02358c2cdf060a190 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 14 Nov 2024 09:00:19 +0100 Subject: [PATCH] feat: refs #8057 Added data updates --- .../11346-yellowPhormium/00-address.sql | 23 +++++++++++++-- .../11346-yellowPhormium/01-client.sql | 29 +++++++++++++++---- .../11346-yellowPhormium/02-supplier.sql | 27 +++++++++++++---- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/db/versions/11346-yellowPhormium/00-address.sql b/db/versions/11346-yellowPhormium/00-address.sql index 02e09bd00..8e1315072 100644 --- a/db/versions/11346-yellowPhormium/00-address.sql +++ b/db/versions/11346-yellowPhormium/00-address.sql @@ -1,4 +1,21 @@ ALTER TABLE vn.address - ADD geoFk int(11) DEFAULT NULL NULL AFTER isLogifloraAllowed, - ADD CONSTRAINT address_zoneGeo_FK FOREIGN KEY (geoFk) - REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + ADD geoFk int(11) DEFAULT NULL NULL AFTER isLogifloraAllowed, + ADD CONSTRAINT address_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +CREATE OR REPLACE TEMPORARY TABLE tAddressGeo + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT a.id, p.geoFk + FROM address a + JOIN town t ON t.provinceFk = a.provinceFk + JOIN postCode p ON p.townFk = t.id + AND p.`code` = a.postalCode + GROUP BY a.id + ORDER BY (a.city SOUNDS LIKE t.`name`) DESC; + +UPDATE address a + JOIN tAddressGeo tag ON tag.id = a.id + SET a.geoFk = tag.geoFk; + +DROP TEMPORARY TABLE tAddressGeo; diff --git a/db/versions/11346-yellowPhormium/01-client.sql b/db/versions/11346-yellowPhormium/01-client.sql index c58810fb1..932b28ef5 100644 --- a/db/versions/11346-yellowPhormium/01-client.sql +++ b/db/versions/11346-yellowPhormium/01-client.sql @@ -1,7 +1,24 @@ ALTER TABLE vn.client - CHANGE hasDailyInvoice hasDailyInvoice tinyint(1) DEFAULT 0 NOT NULL - COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice' - AFTER recommendedCredit, - ADD geoFk int(11) DEFAULT NULL NULL AFTER hasDailyInvoice, - ADD CONSTRAINT client_zoneGeo_FK FOREIGN KEY (geoFk) - REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + CHANGE hasDailyInvoice hasDailyInvoice tinyint(1) DEFAULT 0 NOT NULL + COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice' + AFTER recommendedCredit, + ADD geoFk int(11) DEFAULT NULL NULL AFTER hasDailyInvoice, + ADD CONSTRAINT client_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +CREATE OR REPLACE TEMPORARY TABLE tClientGeo + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT c.id, p.geoFk + FROM client c + JOIN town t ON t.provinceFk = c.provinceFk + JOIN postCode p ON p.townFk = t.id + AND p.`code` = c.postcode + GROUP BY c.id + ORDER BY (c.city SOUNDS LIKE t.`name`) DESC; + +UPDATE client c + JOIN tClientGeo tcg ON tcg.id = c.id + SET c.geoFk = tcg.geoFk; + +DROP TEMPORARY TABLE tClientGeo; diff --git a/db/versions/11346-yellowPhormium/02-supplier.sql b/db/versions/11346-yellowPhormium/02-supplier.sql index f38202d5e..ef5e04a43 100644 --- a/db/versions/11346-yellowPhormium/02-supplier.sql +++ b/db/versions/11346-yellowPhormium/02-supplier.sql @@ -1,6 +1,23 @@ ALTER TABLE vn.supplier - CHANGE companySize companySize enum('small','medium','big') CHARACTER SET utf8mb3 - COLLATE utf8mb3_general_ci DEFAULT NULL NULL AFTER stamp, - ADD geoFk int(11) DEFAULT NULL NULL AFTER companySize, - ADD CONSTRAINT supplier_zoneGeo_FK FOREIGN KEY (geoFk) - REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + CHANGE companySize companySize enum('small','medium','big') CHARACTER SET utf8mb3 + COLLATE utf8mb3_general_ci DEFAULT NULL NULL AFTER stamp, + ADD geoFk int(11) DEFAULT NULL NULL AFTER companySize, + ADD CONSTRAINT supplier_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +CREATE OR REPLACE TEMPORARY TABLE tSupplierGeo + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT sa.supplierFk id, p.geoFk + FROM supplierAddress sa + JOIN town t ON t.provinceFk = sa.provinceFk + JOIN postCode p ON p.townFk = t.id + AND p.`code` = sa.postalCode + GROUP BY sa.supplierFk + ORDER BY (sa.city SOUNDS LIKE t.`name`) DESC; + +UPDATE supplier s + JOIN tSupplierGeo tsg ON tsg.id = s.id + SET s.geoFk = tsg.geoFk; + +DROP TEMPORARY TABLE tSupplierGeo;