42. Add address, and link it to person

This commit is contained in:
Mathieu Jaumotte 2023-03-01 21:20:19 +01:00
parent 139dd6209a
commit 1a6f3953ca

View File

@ -263,9 +263,17 @@ INSERT INTO chill_person_person (
*/ */
FROM import.personnes ip; 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 -- ajouter dans chill_person_accompanying_course
@ -275,6 +283,12 @@ FROM import.personnes ip;
-- DOWN -- 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. -- Undo 41.
DELETE FROM chill_person_person cpp USING import.personnes ip WHERE cpp.id = ip.person_id; 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)); SELECT setval('chill_person_person_id_seq', (SELECT max(id) FROM chill_person_person));