From 7b4f04ef401e03c086b48b75a7f49ede58f002ee Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 17 Feb 2023 09:49:16 +0100 Subject: [PATCH] 11. complete scopes table --- sql/import.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sql/import.sql b/sql/import.sql index 3720c8f..e852b44 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -98,6 +98,13 @@ INSERT INTO chill_main_user_job (id, label, active) FROM ( SELECT DISTINCT ON (job) job1 FROM import.choix_periodes WHERE job1 IS NOT NULL ) t WHERE NOT EXISTS( SELECT 1 FROM chill_main_user_job WHERE label::jsonb = t.job1 ); +-- 11. Complete acp_scopes +ALTER TABLE import.choix_periodes ADD COLUMN acp_scopes1 JSONB; +UPDATE import.choix_periodes SET acp_scopes1=json_build_object('fr', trim(acp_scopes)) WHERE acp_scopes!=''; +INSERT INTO scopes (id, name, active) + SELECT nextval('scopes_id_seq'), t.acp_scopes1, true + FROM ( SELECT DISTINCT ON (acp_scopes) acp_scopes1 FROM import.choix_periodes WHERE acp_scopes1 IS NOT NULL ) t + WHERE NOT EXISTS ( SELECT 1 FROM scopes WHERE name::jsonb = t.acp_scopes1 ); @@ -106,6 +113,10 @@ INSERT INTO chill_main_user_job (id, label, active) -- DOWN -- +-- Undo 11. +DELETE FROM scopes USING import.choix_periodes icp WHERE scopes.name::jsonb = icp.acp_scopes1::jsonb; +SELECT setval('scopes_id_seq', (SELECT max(id) FROM scopes)); +ALTER TABLE import.choix_periodes DROP COLUMN acp_scopes1; -- Undo 10. DELETE FROM chill_main_user_job cmuj USING import.choix_periodes icp WHERE cmuj.label::jsonb = icp.job1::jsonb;