56. Link socialissues to periods
This commit is contained in:
parent
314e625c91
commit
1adf47e63e
@ -315,6 +315,7 @@ INSERT INTO chill_person_household_composition (id, household_id, startdate, hou
|
|||||||
FROM import.personnes
|
FROM import.personnes
|
||||||
WHERE household_composition_type1 IS NOT NULL ;
|
WHERE household_composition_type1 IS NOT NULL ;
|
||||||
|
|
||||||
|
|
||||||
-- 50. Prepare id mapping before insertion
|
-- 50. Prepare id mapping before insertion
|
||||||
ALTER TABLE import.periodes ADD column period_id BIGINT;
|
ALTER TABLE import.periodes ADD column period_id BIGINT;
|
||||||
UPDATE import.periodes SET period_id = periodid
|
UPDATE import.periodes SET period_id = periodid
|
||||||
@ -324,7 +325,8 @@ UPDATE import.periodes SET period_id = periodid
|
|||||||
|
|
||||||
-- 51. Insert in chill_person_accompanying_period
|
-- 51. Insert in chill_person_accompanying_period
|
||||||
INSERT INTO chill_person_accompanying_period (id, openingdate, closingdate, step, remark, intensity, createdby_id, createdat, updatedby_id, updatedat) SELECT
|
INSERT INTO chill_person_accompanying_period (id, openingdate, closingdate, step, remark, intensity, createdby_id, createdat, updatedby_id, updatedat) SELECT
|
||||||
period_id, COALESCE(openingdate1, date(date_trunc('year', CURRENT_DATE))), closingdate1,
|
period_id,
|
||||||
|
COALESCE(openingdate1, date(date_trunc('year', CURRENT_DATE))), closingdate1,
|
||||||
'CONFIRMED', COALESCE(TRIM(remark), ''), intensity1,
|
'CONFIRMED', COALESCE(TRIM(remark), ''), intensity1,
|
||||||
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE,
|
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE,
|
||||||
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE
|
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE
|
||||||
@ -363,6 +365,24 @@ INSERT INTO chill_person_accompanying_period_location_history (id, period_id, st
|
|||||||
FROM chill_person_accompanying_period acp
|
FROM chill_person_accompanying_period acp
|
||||||
WHERE id NOT IN (SELECT period_id FROM chill_person_accompanying_period_location_history) AND step LIKE 'CONFIRMED' ORDER BY id;
|
WHERE id NOT IN (SELECT period_id FROM chill_person_accompanying_period_location_history) AND step LIKE 'CONFIRMED' ORDER BY id;
|
||||||
|
|
||||||
|
-- 56. Link socialIssues to periods
|
||||||
|
INSERT INTO chill_person_accompanying_period_social_issues (accompanyingperiod_id, socialissue_id)
|
||||||
|
SELECT
|
||||||
|
DISTINCT ON (t.period_id) t.period_id,
|
||||||
|
COALESCE(t.enfant_id, t.parent_id, 1) AS socialissue_id -- quid si pas de socialissue ?
|
||||||
|
FROM (
|
||||||
|
SELECT p.period_id,
|
||||||
|
(SELECT id FROM chill_person_social_issue WHERE title::jsonb->>'fr' = icp.parent1::jsonb->>'fr' AND parent_id IS NULL) AS parent_id, icp.parent1,
|
||||||
|
(SELECT id FROM chill_person_social_issue WHERE title::jsonb->>'fr' = icp.enfant1::jsonb->>'fr' AND parent_id =
|
||||||
|
(SELECT id FROM chill_person_social_issue WHERE title::jsonb->>'fr' = icp.parent1::jsonb->>'fr' AND parent_id IS NULL)) AS enfant_id, icp.enfant1
|
||||||
|
FROM import.periodes p
|
||||||
|
JOIN import.choix_periodes icp ON p.acp_socialissues = icp.acp_socialissues
|
||||||
|
ORDER BY id) AS t;
|
||||||
|
|
||||||
|
|
||||||
|
-- 57.
|
||||||
|
-- 58.
|
||||||
|
-- 59.
|
||||||
|
|
||||||
-- ========================================================================================= --
|
-- ========================================================================================= --
|
||||||
|
|
||||||
@ -370,6 +390,13 @@ INSERT INTO chill_person_accompanying_period_location_history (id, period_id, st
|
|||||||
-- DOWN
|
-- DOWN
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- Undo 59.
|
||||||
|
-- Undo 58.
|
||||||
|
-- Undo 57.
|
||||||
|
|
||||||
|
-- Undo 56.
|
||||||
|
DELETE FROM chill_person_accompanying_period_social_issues asi USING import.periodes ip WHERE asi.accompanyingperiod_id = ip.period_id;
|
||||||
|
|
||||||
-- Undo 55.
|
-- Undo 55.
|
||||||
DELETE FROM chill_person_accompanying_period_location_history history USING import.periodes ip WHERE history.period_id = ip.period_id;
|
DELETE FROM chill_person_accompanying_period_location_history history USING import.periodes ip WHERE history.period_id = ip.period_id;
|
||||||
SELECT setval('chill_person_accompanying_period_location_history_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period_location_history));
|
SELECT setval('chill_person_accompanying_period_location_history_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period_location_history));
|
||||||
|
Loading…
Reference in New Issue
Block a user