From 314e625c917d0391c3c7a3b03b28146542f86301 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 10 Mar 2023 19:58:25 +0100 Subject: [PATCH] 55. Copy period in period_location_history --- sql/import.sql | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sql/import.sql b/sql/import.sql index ef0a2df..fec705a 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -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;