From 5a6daae5a44b7e0250a2b6c27386a3c7413dca12 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 8 Mar 2023 21:06:33 +0100 Subject: [PATCH] 43-44. Insert household and link to person, address, position --- sql/import.sql | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sql/import.sql b/sql/import.sql index 4a68df9..3c36358 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -276,6 +276,22 @@ INSERT INTO chill_main_address (id, postcode_id, street, streetnumber, extra, va SELECT ip.person_id, ip.address_id FROM import.personnes ip ; -- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, addr.* FROM chill_main_address addr RIGHT JOIN import.personnes ip ON addr.id = ip.address_id ORDER BY ip.id; +-- 43. Add houshold and household member with position +INSERT INTO chill_person_household (id) SELECT person_id from import.personnes; +SELECT setval('chill_person_household_id_seq', (SELECT max(id) FROM chill_person_household)); +INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, sharedhousehold, position_id, holder) SELECT + nextval('chill_person_household_members_id_seq'), person_id, person_id, COALESCE(household_startdate1, CURRENT_DATE), + true, (SELECT id FROM chill_person_household_position pos WHERE household_position1::jsonb->>'fr' = pos.label::jsonb->>'fr'), false + FROM import.personnes; +-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, hh.* FROM chill_person_household hh FULL JOIN import.personnes ip ON hh.id = ip.person_id ORDER BY hh.id; +-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, memb.* FROM chill_person_household_members memb JOIN import.personnes ip ON memb.household_id = ip.person_id ORDER BY memb.household_id; + +-- 44. Add address to household +INSERT INTO chill_person_household_to_addresses (household_id, address_id) SELECT person_id, address_id + FROM import.personnes WHERE postcode_id IS NOT NULL; -- cfr (*) adresse insérées seulement si postcode + +-- 45. Add household composition +-- (not yet implemented in canvas) -- ========================================================================================= -- @@ -284,6 +300,15 @@ SELECT ip.person_id, ip.address_id FROM import.personnes ip ; -- DOWN -- +-- Undo 44. +DELETE FROM chill_person_household_to_addresses cphta USING import.personnes ic WHERE cphta.household_id = ic.person_id ; + +-- Undo 43. +DELETE FROM chill_person_household_members cphm USING import.personnes ic WHERE cphm.person_id = ic.person_id; +SELECT setval('chill_person_household_members_id_seq', (SELECT max(id) FROM chill_person_household_members)); +DELETE FROM chill_person_household cph USING import.personnes ip WHERE cph.id = ip.person_id; +SELECT setval('chill_person_household_id_seq', (SELECT max(id) FROM chill_person_household)); + -- 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)); @@ -412,4 +437,8 @@ ALTER TABLE import.periodes DROP COLUMN closingdate1; -- ------------- -- tiers choices_list: civility kind profession category - +-- ============= +-- QUESTIONS +-- +-- définir par défaut: quel user, quel centre ? +--