Compare commits
No commits in common. "b68e0399ccd8f8a4b64e561be90f84b7f043dda9" and "d9152fc090cc6f3ace4ad7161916e7ce3beb2f25" have entirely different histories.
b68e0399cc
...
d9152fc090
@ -369,11 +369,7 @@ INSERT INTO chill_person_accompanying_period_location_history (id, period_id, st
|
|||||||
INSERT INTO chill_person_accompanying_period_social_issues (accompanyingperiod_id, socialissue_id)
|
INSERT INTO chill_person_accompanying_period_social_issues (accompanyingperiod_id, socialissue_id)
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT ON (t.period_id) t.period_id,
|
DISTINCT ON (t.period_id) t.period_id,
|
||||||
COALESCE(
|
COALESCE(t.enfant_id, t.parent_id, 1) AS socialissue_id -- quid si pas de socialissue ?
|
||||||
t.enfant_id,
|
|
||||||
t.parent_id,
|
|
||||||
1 -- default value ?
|
|
||||||
) AS socialissue_id
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT p.period_id,
|
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,
|
(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,
|
||||||
@ -385,10 +381,7 @@ FROM (
|
|||||||
|
|
||||||
-- 57. Link referrer to periods
|
-- 57. Link referrer to periods
|
||||||
UPDATE chill_person_accompanying_period acp
|
UPDATE chill_person_accompanying_period acp
|
||||||
SET user_id = COALESCE(
|
SET user_id = (SELECT id FROM users WHERE users.username = ip.referrer)
|
||||||
(SELECT id FROM users WHERE users.username = ip.referrer),
|
|
||||||
1 -- default value ?
|
|
||||||
)
|
|
||||||
FROM import.periodes ip WHERE acp.id = ip.period_id;
|
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;
|
--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;
|
||||||
|
|
||||||
@ -396,7 +389,7 @@ UPDATE chill_person_accompanying_period acp
|
|||||||
INSERT INTO accompanying_periods_scopes (accompanying_period_id, scope_id)
|
INSERT INTO accompanying_periods_scopes (accompanying_period_id, scope_id)
|
||||||
SELECT ip.period_id, COALESCE(
|
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 ip.acp_scopes1::jsonb->>'fr' = s.name::jsonb->>'fr'),
|
||||||
(SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default value 'tous'
|
(SELECT id from scopes s WHERE s.name::jsonb->>'fr' = 'tous') -- default 'tous'
|
||||||
)
|
)
|
||||||
FROM import.periodes ip;
|
FROM import.periodes ip;
|
||||||
|
|
||||||
@ -411,50 +404,6 @@ 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')
|
(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;
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
-- ========================================================================================= --
|
-- ========================================================================================= --
|
||||||
|
|
||||||
@ -462,20 +411,6 @@ FROM import.periodes ip WHERE acp.id = ip.period_id;
|
|||||||
-- DOWN
|
-- 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.
|
-- Undo 60.
|
||||||
UPDATE chill_person_accompanying_period acp SET job_id = null FROM import.periodes ip WHERE acp.id = ip.period_id;
|
UPDATE chill_person_accompanying_period acp SET job_id = null FROM import.periodes ip WHERE acp.id = ip.period_id;
|
||||||
|
|
||||||
@ -664,6 +599,8 @@ ALTER TABLE import.periodes DROP COLUMN openingdate1;
|
|||||||
ALTER TABLE import.periodes DROP COLUMN closingdate1;
|
ALTER TABLE import.periodes DROP COLUMN closingdate1;
|
||||||
|
|
||||||
|
|
||||||
|
-- -------------
|
||||||
|
-- tiers choices_list: civility kind profession category
|
||||||
|
|
||||||
-- =============
|
-- =============
|
||||||
-- QUESTIONS
|
-- QUESTIONS
|
||||||
|
Loading…
Reference in New Issue
Block a user