From 6900d66206092b7197e266be421c2272e3a3bca8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 10 Mar 2023 18:32:09 +0100 Subject: [PATCH] 52. Link participations to periods --- sql/import.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sql/import.sql b/sql/import.sql index b8e8cee..22ba61d 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -330,12 +330,21 @@ INSERT INTO chill_person_accompanying_period (id, openingdate, step, remark, int FROM import.periodes; SELECT setval('chill_person_accompanying_period_id_seq', (SELECT max(id) FROM chill_person_accompanying_period)); +-- 52. Link participations to periods +INSERT INTO chill_person_accompanying_period_participation (id, person_id, accompanyingperiod_id, startdate) SELECT + nextval('chill_person_accompanying_period_participation_id_seq'), t.person_id, t.period_id, date(date_trunc('year', CURRENT_DATE)) + FROM (SELECT person_id, period_id FROM import.periodes ip JOIN import.personnes p ON ip.id = p.id ORDER BY person_id) AS t; + -- ========================================================================================= -- -- -- DOWN -- +-- Undo 52. +DELETE FROM chill_person_accompanying_period_participation part USING import.periodes ip WHERE part.accompanyingperiod_id = ip.period_id; +SELECT setval('chill_person_accompanying_period_participation_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period_participation)); + -- Undo 51. DELETE FROM chill_person_accompanying_period acp USING import.periodes ip WHERE acp.id = ip.period_id; SELECT setval('chill_person_accompanying_period_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period));