62-63. Add and link comments to periods, pin last comment
This commit is contained in:
parent
07df6c4292
commit
b68e0399cc
@ -411,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)
|
||||
|
||||
|
||||
-- ========================================================================================= --
|
||||
|
||||
@ -418,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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user