salix/db/versions/11346-yellowPhormium/01-client.sql

25 lines
849 B
MySQL
Raw Normal View History

2024-11-14 07:24:42 +00:00
ALTER TABLE vn.client
2024-11-14 08:00:19 +00:00
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;
2024-11-18 11:53:36 +00:00
CREATE OR REPLACE TEMPORARY TABLE tmp.tClientGeo
2024-11-14 08:00:19 +00:00
(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
GROUP BY c.id
2024-11-18 09:52:41 +00:00
ORDER BY (c.city SOUNDS LIKE t.`name`) DESC,
(p.code = c.postcode) DESC;
2024-11-14 08:00:19 +00:00
UPDATE client c
2024-11-18 11:53:36 +00:00
JOIN tmp.tClientGeo tcg ON tcg.id = c.id
2024-11-14 08:00:19 +00:00
SET c.geoFk = tcg.geoFk;
2024-11-18 11:53:36 +00:00
DROP TEMPORARY TABLE tmp.tClientGeo;