7. complete chill_person_household_position table

This commit is contained in:
Mathieu Jaumotte 2023-02-15 21:57:36 +01:00
parent de8450267d
commit 32da5540fe

View File

@ -58,11 +58,27 @@ INSERT INTO chill_person_household_composition_type (id, active, label)
FROM ( SELECT DISTINCT ON (household_composition_type) household_composition_type1 FROM import.choix_personnes WHERE household_composition_type1 IS NOT NULL ) t
WHERE NOT EXISTS ( SELECT 1 FROM chill_person_household_composition_type WHERE label::jsonb = t.household_composition_type1 );
-- 7. Complete table household_position
ALTER TABLE import.choix_personnes ADD COLUMN household_position1 JSONB;
UPDATE import.choix_personnes SET household_position1=json_build_object('fr', trim(household_position)) WHERE household_position!='';
WITH max_ordering AS ( SELECT MAX(ordering) as max_ordering FROM chill_person_household_position )
INSERT INTO chill_person_household_position (id, label, sharehousehold, allowholder, ordering)
SELECT
nextval('chill_person_household_position_id_seq'), t.household_position1, true, false,
max_ordering.max_ordering + row_number() OVER () as ordering
FROM ( SELECT DISTINCT ON (household_position) household_position1 FROM import.choix_personnes WHERE household_position1 IS NOT NULL ) t
CROSS JOIN max_ordering
WHERE NOT EXISTS ( SELECT 1 FROM chill_person_household_position WHERE label::jsonb = t.household_position1 );
--
-- DOWN
--
-- Undo 7.
DELETE FROM chill_person_household_position cphp USING import.choix_personnes icp WHERE cphp.label::jsonb = icp.household_position1::jsonb;
SELECT setval('chill_person_household_position_id_seq', (SELECT max(id) FROM chill_person_household_position));
ALTER TABLE import.choix_personnes DROP COLUMN household_position1;
-- Undo 6.
DELETE FROM chill_person_household_composition_type cphct USING import.choix_personnes icp WHERE cphct.label::jsonb = icp.household_composition_type1::jsonb AND cphct.id > 6;
SELECT setval('chill_person_household_composition_type_id_seq', (SELECT max(id) FROM chill_person_household_composition_type));
@ -93,7 +109,7 @@ ALTER TABLE import.periodes DROP COLUMN closingdate1;
-- -------------
-- personnes choices_list: gender household_position
-- personnes choices_list: gender
-- periodes choices_list: intensity referrer job acp_scopes acp_socialissues work_socialaction
-- tiers choices_list: civility kind profession category