58. Link scopes to periods

This commit is contained in:
Mathieu Jaumotte 2023-03-11 15:11:47 +01:00
parent 7893eb3c81
commit 264fdb5888

View File

@ -385,8 +385,20 @@ UPDATE chill_person_accompanying_period acp
FROM import.periodes ip WHERE acp.id = ip.period_id;
--SELECT ip.id, (SELECT id FROM users WHERE users.username = ip.referrer) AS referrer_id, ip.referrer, acp.id as period_id, acp.user_id FROM chill_person_accompanying_period acp JOIN import.periodes ip ON ip.period_id = acp.id ORDER BY ip.id;
-- 58.
-- 59.
-- 58. Link scopes to periods
INSERT INTO accompanying_periods_scopes (accompanying_period_id, scope_id)
SELECT ip.period_id, COALESCE(
(SELECT id FROM scopes s WHERE ip.acp_scopes1::jsonb->>'fr' = s.name::jsonb->>'fr'),
(SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default 'tous'
)
FROM import.periodes ip;
-- 59. Link origin to periods
UPDATE chill_person_accompanying_period acp SET origin_id =
(SELECT id FROM chill_person_accompanying_period_origin o WHERE o.label::jsonb->>'fr' = ip.origin1::jsonb->>'fr' )
FROM import.periodes ip WHERE acp.id = ip.period_id;
--SELECT ip.id, ip.origin1, acp.id as period_id, acp.origin_id FROM chill_person_accompanying_period acp JOIN import.periodes ip ON ip.period_id = acp.id ORDER BY ip.id;
-- ========================================================================================= --
@ -396,6 +408,8 @@ UPDATE chill_person_accompanying_period acp
-- Undo 59.
-- Undo 58.
DELETE FROM accompanying_periods_scopes acs USING import.periodes ip WHERE acs.accompanying_period_id = ip.period_id;
-- Undo 57.
UPDATE chill_person_accompanying_period acp SET user_id = null FROM import.periodes ip WHERE ip.period_id = acp.id;