12. complete users table (referrer)

This commit is contained in:
Mathieu Jaumotte 2023-02-17 17:53:54 +01:00
parent 7b4f04ef40
commit e14f6896e3

View File

@ -106,13 +106,21 @@ INSERT INTO scopes (id, name, active)
FROM ( SELECT DISTINCT ON (acp_scopes) acp_scopes1 FROM import.choix_periodes WHERE acp_scopes1 IS NOT NULL ) t 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 ); WHERE NOT EXISTS ( SELECT 1 FROM scopes WHERE name::jsonb = t.acp_scopes1 );
-- 12. Complete referrers
INSERT INTO users (id, username, password, enabled, locked, attributes, label)
SELECT nextval('users_id_seq'), t.referrer, '', false, false, '[]', t.referrer
FROM ( SELECT DISTINCT ON (referrer) referrer FROM import.choix_periodes WHERE referrer <> '') t
WHERE NOT EXISTS ( SELECT 1 FROM users WHERE username::text = t.referrer );
-- --
-- DOWN -- DOWN
-- --
-- Undo 12.
DELETE FROM users USING import.choix_periodes icp WHERE users.username::text = icp.referrer::text AND users.password = '' AND users.enabled = false;
SELECT setval('users_id_seq', (SELECT COALESCE(max(id),1) FROM users));
-- Undo 11. -- Undo 11.
DELETE FROM scopes USING import.choix_periodes icp WHERE scopes.name::jsonb = icp.acp_scopes1::jsonb; 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)); SELECT setval('scopes_id_seq', (SELECT max(id) FROM scopes));