43-44. Insert household and link to person, address, position

This commit is contained in:
Mathieu Jaumotte 2023-03-08 21:06:33 +01:00
parent 3978ee8b1a
commit 5a6daae5a4

View File

@ -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.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; -- 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 -- 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. -- Undo 42.
DELETE FROM chill_main_address cma USING import.personnes ip WHERE cma.id = ip.address_id; 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)); 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 -- tiers choices_list: civility kind profession category
-- =============
-- QUESTIONS
--
-- définir par défaut: quel user, quel centre ?
--