52. Link participations to periods

This commit is contained in:
Mathieu Jaumotte 2023-03-10 18:32:09 +01:00
parent f513dd1b36
commit 6900d66206

View File

@ -330,12 +330,21 @@ INSERT INTO chill_person_accompanying_period (id, openingdate, step, remark, int
FROM import.periodes; FROM import.periodes;
SELECT setval('chill_person_accompanying_period_id_seq', (SELECT max(id) FROM chill_person_accompanying_period)); 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 -- 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. -- Undo 51.
DELETE FROM chill_person_accompanying_period acp USING import.periodes ip WHERE acp.id = ip.period_id; 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)); SELECT setval('chill_person_accompanying_period_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period));