From 264fdb58888a8949f1004f42a201e9ea672ea147 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 11 Mar 2023 15:11:47 +0100 Subject: [PATCH] 58. Link scopes to periods --- sql/import.sql | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sql/import.sql b/sql/import.sql index ddca6e3..6aeb3dd 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -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;