11. complete scopes table

This commit is contained in:
Mathieu Jaumotte 2023-02-17 09:49:16 +01:00
parent 6d64060965
commit 7b4f04ef40

View File

@ -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 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 ); 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 -- 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. -- Undo 10.
DELETE FROM chill_main_user_job cmuj USING import.choix_periodes icp WHERE cmuj.label::jsonb = icp.job1::jsonb; DELETE FROM chill_main_user_job cmuj USING import.choix_periodes icp WHERE cmuj.label::jsonb = icp.job1::jsonb;