50-51. Insert in accompanyingPeriods table
This commit is contained in:
parent
477565f6e1
commit
67d020d322
@ -313,6 +313,19 @@ INSERT INTO chill_person_household_composition (id, household_id, startdate, hou
|
|||||||
FROM import.personnes
|
FROM import.personnes
|
||||||
WHERE household_composition_type1 IS NOT NULL ;
|
WHERE household_composition_type1 IS NOT NULL ;
|
||||||
|
|
||||||
|
-- 50. Prepare id mapping before insertion
|
||||||
|
ALTER TABLE import.periodes ADD column period_id BIGINT;
|
||||||
|
UPDATE import.periodes SET period_id = periodid
|
||||||
|
FROM (SELECT id, nextval('chill_person_accompanying_period_id_seq') AS periodid FROM import.periodes ORDER BY id) AS t
|
||||||
|
WHERE import.periodes.id = t.id;
|
||||||
|
--SELECT ipe.id, ipe.fullname, ipe.period_id, ip.id, ip.person_id FROM import.periodes ipe JOIN import.personnes ip ON ipe.id = ip.id ORDER BY ipe.id;
|
||||||
|
|
||||||
|
-- 51. Insert in chill_person_accompanying_period
|
||||||
|
INSERT INTO chill_person_accompanying_period (id, openingdate, step, remark, intensity, createdby_id, createdat, updatedby_id, updatedat) SELECT
|
||||||
|
period_id, date(date_trunc('year', CURRENT_DATE)), 'CONFIRMED', COALESCE(TRIM(remark), ''), intensity1,
|
||||||
|
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE,
|
||||||
|
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), CURRENT_DATE
|
||||||
|
FROM import.periodes;
|
||||||
|
|
||||||
-- ========================================================================================= --
|
-- ========================================================================================= --
|
||||||
|
|
||||||
@ -320,6 +333,13 @@ WHERE household_composition_type1 IS NOT NULL ;
|
|||||||
-- DOWN
|
-- DOWN
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- Undo 51.
|
||||||
|
DELETE FROM chill_person_accompanying_period acp USING import.periodes ip WHERE acp.id = ip.period_id;
|
||||||
|
SELECT setval('chill_person_accompanying_period_id_seq', (SELECT COALESCE(max(id), 1) FROM chill_person_accompanying_period));
|
||||||
|
|
||||||
|
-- Undo 50.
|
||||||
|
ALTER TABLE import.periodes DROP column period_id;
|
||||||
|
|
||||||
-- Undo 46.
|
-- Undo 46.
|
||||||
DELETE FROM chill_person_household_composition c USING import.personnes ip WHERE c.household_id = ip.person_id;
|
DELETE FROM chill_person_household_composition c USING import.personnes ip WHERE c.household_id = ip.person_id;
|
||||||
SELECT setval('chill_person_household_composition_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_composition));
|
SELECT setval('chill_person_household_composition_id_seq', (SELECT COALESCE(max(id),1) FROM chill_person_household_composition));
|
||||||
|
Loading…
Reference in New Issue
Block a user