From 396444790f448e65381c711095482006f91dee67 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 17 Feb 2023 09:43:37 +0100 Subject: [PATCH] 9. complete chill_person_accompanying_period_origin table --- sql/import.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sql/import.sql b/sql/import.sql index f7285bc..fc6cdf3 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -82,11 +82,22 @@ INSERT INTO chill_person_accompanying_period_closingmotive (id, name, active, pa CROSS JOIN max_ordering WHERE NOT EXISTS ( SELECT 1 FROM chill_person_accompanying_period_closingmotive WHERE name::jsonb = t.closingmotive1 ); +-- 9. Complete origin +ALTER TABLE import.choix_periodes ADD COLUMN origin1 JSONB; +UPDATE import.choix_periodes SET origin1=json_build_object('fr', trim(origin)) WHERE origin!=''; +INSERT INTO chill_person_accompanying_period_origin (id, label, noactiveafter) + SELECT nextval('chill_person_accompanying_period_origin_id_seq'), t.origin1, null + FROM ( SELECT DISTINCT ON (origin) origin1 FROM import.choix_periodes WHERE origin1 IS NOT NULL ) t + WHERE NOT EXISTS ( SELECT 1 FROM chill_person_accompanying_period_origin WHERE label::jsonb = t.origin1 ); -- -- DOWN -- +-- Undo 9. +DELETE FROM chill_person_accompanying_period_origin cpapo USING import.choix_periodes icp WHERE cpapo.label::jsonb = icp.origin1::jsonb; +SELECT setval('chill_person_accompanying_period_origin_id_seq', (SELECT max(id) FROM chill_person_accompanying_period_origin)); +ALTER TABLE import.choix_periodes DROP COLUMN origin1; -- Undo 8. DELETE FROM chill_person_accompanying_period_closingmotive cpapcm USING import.choix_periodes icp WHERE cpapcm.name::jsonb = icp.closingmotive1::jsonb;