55. Copy period in period_location_history

This commit is contained in:
Mathieu Jaumotte 2023-03-10 19:58:25 +01:00
parent 59daee4790
commit 314e625c91

View File

@ -323,8 +323,9 @@ UPDATE import.periodes SET period_id = periodid
--SELECT ipe.id, ipe.fullname, ipe.period_id, ip.id, ip.person_id FROM import.periodes ipe JOIN import.personnes ip ON ipe.id = ip.id ORDER BY ipe.id;
-- 51. Insert in chill_person_accompanying_period
INSERT INTO chill_person_accompanying_period (id, openingdate, step, remark, intensity, createdby_id, createdat, updatedby_id, updatedat) SELECT
period_id, date(date_trunc('year', CURRENT_DATE)), 'CONFIRMED', COALESCE(TRIM(remark), ''), intensity1,
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,
'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
FROM import.periodes;
@ -354,6 +355,14 @@ UPDATE chill_person_accompanying_period acp
FROM import.personnes pson JOIN import.periodes piod ON pson.id = piod.id
WHERE piod.period_id = acp.id AND piod.personlocation = 'oui';
-- 55. Copy period in period_location_history
INSERT INTO chill_person_accompanying_period_location_history (id, period_id, startdate, enddate, personlocation_id, addresslocation_id, createdat, createdby_id)
SELECT
nextval('chill_person_accompanying_period_location_history_id_seq'), id, acp.openingdate, acp.closingdate,
acp.personlocation_id, acp.addresslocation_id, acp.createdat, acp.createdby_id
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;
-- ========================================================================================= --
@ -361,6 +370,10 @@ UPDATE chill_person_accompanying_period acp
-- DOWN
--
-- Undo 55.
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));
-- Undo 54.
UPDATE chill_person_accompanying_period acp SET addresslocation_id = NULL, personlocation_id = NULL FROM import.periodes piod WHERE piod.period_id = acp.id;