salix/db/versions/11346-yellowPhormium/00-address.sql

24 lines
750 B
MySQL
Raw Permalink Normal View History

2024-11-14 07:24:42 +00:00
ALTER TABLE vn.address
2024-11-14 08:00:19 +00:00
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;
2024-11-18 11:53:36 +00:00
CREATE OR REPLACE TEMPORARY TABLE tmp.tAddressGeo
2024-11-14 08:00:19 +00:00
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT a.id, p.geoFk
2024-11-18 11:56:37 +00:00
FROM vn.address a
JOIN vn.town t ON t.provinceFk = a.provinceFk
JOIN vn.postCode p ON p.townFk = t.id
AND (p.code = a.postalCode OR a.postalCode IS NULL)
2024-11-18 12:09:33 +00:00
JOIN vn.zoneGeo zg ON zg.id = p.geoFk
2024-11-14 08:00:19 +00:00
GROUP BY a.id
2024-11-18 09:52:41 +00:00
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC,
(p.code = a.postalCode) DESC;
2024-11-14 08:00:19 +00:00
2024-11-18 11:56:37 +00:00
UPDATE vn.address a
2024-11-18 11:53:36 +00:00
JOIN tmp.tAddressGeo tag ON tag.id = a.id
2024-11-14 08:00:19 +00:00
SET a.geoFk = tag.geoFk;
2024-11-18 11:53:36 +00:00
DROP TEMPORARY TABLE tmp.tAddressGeo;