From 85a1680b777be6ae6213227860464181d486ff42 Mon Sep 17 00:00:00 2001 From: John OHara Date: Tue, 24 Dec 2024 09:06:09 +0000 Subject: [PATCH] Datastore config migration --- .../tools/horreum/svc/ConfigServiceImpl.java | 5 +- .../src/main/resources/db/changeLog.xml | 65 ++++++++++++++++++- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ConfigServiceImpl.java b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ConfigServiceImpl.java index 0d8c62425..c265e61fc 100644 --- a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ConfigServiceImpl.java +++ b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ConfigServiceImpl.java @@ -32,10 +32,9 @@ public class ConfigServiceImpl implements ConfigService { //cache available dataStore configurations private static final List datastoreTypes = Arrays.asList( - DatastoreType.values()).stream() + DatastoreType.values()).stream() .map(type -> type.getConfig()) - .collect(Collectors.toList() - ); + .collect(Collectors.toList()); @ConfigProperty(name = "horreum.privacy") Optional privacyStatement; diff --git a/horreum-backend/src/main/resources/db/changeLog.xml b/horreum-backend/src/main/resources/db/changeLog.xml index bf6b29a7d..b2e5f2f4d 100644 --- a/horreum-backend/src/main/resources/db/changeLog.xml +++ b/horreum-backend/src/main/resources/db/changeLog.xml @@ -4688,12 +4688,75 @@ $$ LANGUAGE plpgsql; + ANY + UPDATE backendconfig SET configuration = '{"builtIn": true, "authentication": {"type": "none"}}' - WHERE id = 1; + WHERE id = 1 + + + + UPDATE backendconfig + SET configuration = updated.newConfig + FROM (select id, jsonb_insert(newConfig - 'apiKey' - 'username' - 'password', '{authentication,type}', '"none"') as newConfig + from (select + id, + jsonb_insert(configuration, '{authentication}', '{}') as newConfig + from backendconfig + where jsonb_path_exists(configuration, '$.apiKey') + AND configuration ->> 'apiKey' = '' + AND not jsonb_path_exists(configuration, '$.username')) + ) + as updated + WHERE backendconfig.id = updated.id; + + + + + UPDATE backendconfig + SET configuration = updated.newConfig + FROM (select id, jsonb_insert(newConfig, '{authentication,type}', '"api-key"') as newConfig + from (Select rootConfig.id, + jsonb_insert(rootConfig.newConfig - 'apiKey' - 'username' - 'password', '{authentication,apiKey}', + to_jsonb(rootConfig.apiKey)) as newConfig + FROM (select id, + name, + configuration ->> 'apiKey' as apiKey, + configuration, + jsonb_insert(configuration, '{authentication}', '{}') as newConfig + from backendconfig + where jsonb_path_exists(configuration, '$.apiKey') + AND not configuration ->> 'apiKey' = '' + and not jsonb_path_exists(configuration, '$.authentication')) + as rootConfig) + as updated) + as updated + WHERE backendconfig.id = updated.id + + + + + UPDATE backendconfig + SET configuration = updated.newConfig + FROM + (select id, jsonb_insert(newConfig, '{authentication,type}', '"username"') as newConfig + FROM + (select id, jsonb_insert(updatedConfig.newConfig - 'password', '{authentication,password}', to_jsonb(updatedConfig.password)) as newConfig + from + (Select rootConfig.id, username, password, jsonb_insert(rootConfig.newConfig - 'apiKey' - 'username', '{authentication,username}', to_jsonb(rootConfig.username)) as newConfig + FROM + (select id, name, configuration ->> 'username' as username, configuration ->> 'password' as password, configuration, jsonb_insert(configuration, '{authentication}', '{}') as newConfig + from backendconfig + where jsonb_path_exists(configuration, '$.username') + ) as rootConfig + ) as updatedConfig) + ) as updated + WHERE backendconfig.id = updated.id; + +