From e14f6896e3abcfaf15c03b57db4e5980fdf40268 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 17 Feb 2023 17:53:54 +0100 Subject: [PATCH] 12. complete users table (referrer) --- sql/import.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sql/import.sql b/sql/import.sql index e852b44..1be471d 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -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 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 -- +-- 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. 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));