Compare commits

...

2 Commits

View File

@ -369,7 +369,11 @@ INSERT INTO chill_person_accompanying_period_location_history (id, period_id, st
INSERT INTO chill_person_accompanying_period_social_issues (accompanyingperiod_id, socialissue_id)
SELECT
DISTINCT ON (t.period_id) t.period_id,
COALESCE(t.enfant_id, t.parent_id, 1) AS socialissue_id -- quid si pas de socialissue ?
COALESCE(
t.enfant_id,
t.parent_id,
1 -- default value ?
) AS socialissue_id
FROM (
SELECT p.period_id,
(SELECT id FROM chill_person_social_issue WHERE title::jsonb->>'fr' = icp.parent1::jsonb->>'fr' AND parent_id IS NULL) AS parent_id, icp.parent1,
@ -381,7 +385,10 @@ FROM (
-- 57. Link referrer to periods
UPDATE chill_person_accompanying_period acp
SET user_id = (SELECT id FROM users WHERE users.username = ip.referrer)
SET user_id = COALESCE(
(SELECT id FROM users WHERE users.username = ip.referrer),
1 -- default value ?
)
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;
@ -389,7 +396,7 @@ UPDATE chill_person_accompanying_period acp
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'
(SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default value 'tous'
)
FROM import.periodes ip;
@ -404,6 +411,50 @@ UPDATE chill_person_accompanying_period acp SET job_id =
(SELECT id FROM chill_main_user_job j WHERE j.label::jsonb->>'fr' = ip.job1::jsonb->>'fr')
FROM import.periodes ip WHERE acp.id = ip.period_id;
-- 61. Link administrative Location
-- (to be add in csv)
-- 62. Add and link comments
INSERT INTO chill_person_accompanying_period_comment (id, accompanyingperiod_id, content, creator_id, createdat, updatedby_id, updatedat)
SELECT nextval('chill_person_accompanying_period_comment_id_seq'), period_id, comment1_content,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP
FROM import.periodes ip WHERE ip.comment1_content != '';
INSERT INTO chill_person_accompanying_period_comment (id, accompanyingperiod_id, content, creator_id, createdat, updatedby_id, updatedat)
SELECT nextval('chill_person_accompanying_period_comment_id_seq'), period_id, comment2_content,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP
FROM import.periodes ip WHERE ip.comment2_content != '';
INSERT INTO chill_person_accompanying_period_comment (id, accompanyingperiod_id, content, creator_id, createdat, updatedby_id, updatedat)
SELECT nextval('chill_person_accompanying_period_comment_id_seq'), period_id, comment3_content,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP
FROM import.periodes ip WHERE ip.comment3_content != '';
INSERT INTO chill_person_accompanying_period_comment (id, accompanyingperiod_id, content, creator_id, createdat, updatedby_id, updatedat)
SELECT nextval('chill_person_accompanying_period_comment_id_seq'), period_id, comment4_content,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP
FROM import.periodes ip WHERE ip.comment4_content != '';
INSERT INTO chill_person_accompanying_period_comment (id, accompanyingperiod_id, content, creator_id, createdat, updatedby_id, updatedat)
SELECT nextval('chill_person_accompanying_period_comment_id_seq'), period_id, comment5_content,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP,
(SELECT user_id FROM chill_person_accompanying_period acp WHERE acp.id = ip.period_id), CURRENT_TIMESTAMP
FROM import.periodes ip WHERE ip.comment5_content != '';
-- 63. Link pinned comment to period
UPDATE import.periodes SET comment1_content = null WHERE comment1_content = '';
UPDATE import.periodes SET comment2_content = null WHERE comment2_content = '';
UPDATE import.periodes SET comment3_content = null WHERE comment3_content = '';
UPDATE import.periodes SET comment4_content = null WHERE comment4_content = '';
UPDATE import.periodes SET comment5_content = null WHERE comment5_content = '';
UPDATE chill_person_accompanying_period acp SET pinnedcomment_id =
(SELECT id FROM chill_person_accompanying_period_comment com WHERE com.accompanyingperiod_id = acp.id
AND com.content = COALESCE(ip.comment5_content, ip.comment4_content, ip.comment3_content, ip.comment2_content, ip.comment1_content)
LIMIT 1)
FROM import.periodes ip WHERE acp.id = ip.period_id;
-- ~~Link closingmotive~~ (to be removed from csv)
-- ========================================================================================= --
@ -411,6 +462,20 @@ FROM import.periodes ip WHERE acp.id = ip.period_id;
-- DOWN
--
-- Undo 63.
UPDATE chill_person_accompanying_period acp SET pinnedcomment_id = null FROM import.periodes ip WHERE acp.id = ip.period_id;
UPDATE import.periodes SET comment1_content = '' WHERE comment1_content IS NULL;
UPDATE import.periodes SET comment2_content = '' WHERE comment2_content IS NULL;
UPDATE import.periodes SET comment3_content = '' WHERE comment3_content IS NULL;
UPDATE import.periodes SET comment4_content = '' WHERE comment4_content IS NULL;
UPDATE import.periodes SET comment5_content = '' WHERE comment5_content IS NULL;
-- Undo 62.
DELETE FROM chill_person_accompanying_period_comment com USING import.periodes ip WHERE com.accompanyingperiod_id = ip.period_id;
SELECT setval('chill_person_accompanying_period_comment_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period_comment));
-- Undo 61.
-- Undo 60.
UPDATE chill_person_accompanying_period acp SET job_id = null FROM import.periodes ip WHERE acp.id = ip.period_id;
@ -599,8 +664,6 @@ ALTER TABLE import.periodes DROP COLUMN openingdate1;
ALTER TABLE import.periodes DROP COLUMN closingdate1;
-- -------------
-- tiers choices_list: civility kind profession category
-- =============
-- QUESTIONS