From 1a6f3953caa7c9e0b352cd1999745fc07c3fcbea Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Mar 2023 21:20:19 +0100 Subject: [PATCH] 42. Add address, and link it to person --- sql/import.sql | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sql/import.sql b/sql/import.sql index 7bacc94..8dda47e 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -263,9 +263,17 @@ INSERT INTO chill_person_person ( */ FROM import.personnes ip; +-- 42. Add address, and link it to person +ALTER TABLE import.personnes ADD column address_id BIGINT; +UPDATE import.personnes SET address_id = nextval('chill_main_address_id_seq'); +ALTER TABLE import.personnes ADD column postcode_id BIGINT; +UPDATE import.personnes SET postcode_id = cmpc.id FROM chill_main_postal_code cmpc WHERE cmpc.code = postcode AND cmpc.origin = 0; +INSERT INTO chill_main_address (id, postcode_id, street, streetnumber, extra, validFrom) SELECT + address_id, postcode_id, street, streetnumber, extra, CURRENT_DATE +FROM import.personnes WHERE postcode_id IS NOT NULL; + --- country, adresse, -- ajouter dans chill_person_accompanying_course @@ -275,6 +283,12 @@ FROM import.personnes ip; -- DOWN -- +-- Undo 42. +DELETE FROM chill_main_address cma USING import.personnes ip WHERE cma.id = ip.address_id; +SELECT setval('chill_main_address_id_seq', (SELECT max(id) FROM chill_main_address)); +ALTER TABLE import.personnes DROP column postcode_id; +ALTER TABLE import.personnes DROP column address_id; + -- Undo 41. DELETE FROM chill_person_person cpp USING import.personnes ip WHERE cpp.id = ip.person_id; SELECT setval('chill_person_person_id_seq', (SELECT max(id) FROM chill_person_person));