|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<databaseChangeLog |
| 3 | + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" |
| 4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 5 | + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"> |
| 6 | + |
| 7 | + <changeSet id="20260403001" author="Alex"> |
| 8 | + <comment>Refactor SOCAI configuration to support multi-provider presets and visibility rules</comment> |
| 9 | + <sql dbms="postgresql" splitStatements="false"> |
| 10 | + <![CDATA[ |
| 11 | +do $$ |
| 12 | +declare |
| 13 | + grp_id integer; |
| 14 | +begin |
| 15 | + -- 1. Get the Group ID for SOC_AI |
| 16 | + select id into grp_id from public.utm_module_group |
| 17 | + where module_id = (select id from public.utm_module where module_name = 'SOC_AI') |
| 18 | + limit 1; |
| 19 | +
|
| 20 | + IF grp_id IS NOT NULL THEN |
| 21 | + -- 2. Cleanup old keys that might conflict or are being renamed/refactored |
| 22 | + DELETE FROM public.utm_module_group_configuration |
| 23 | + WHERE group_id = grp_id |
| 24 | + AND conf_key IN ('utmstack.socai.custom.url', 'utmstack.socai.custom.model', 'utmstack.socai.provider'); |
| 25 | +
|
| 26 | + -- 3. Update Existing Behavioral Keys (Behavior Section) |
| 27 | + UPDATE public.utm_module_group_configuration |
| 28 | + SET conf_name = 'Auto-create incidents for "possible incident"', |
| 29 | + conf_description = 'If set to "true", the system will create incidents based on analysis of alerts.' |
| 30 | + WHERE group_id = grp_id AND conf_key = 'utmstack.socai.incidentCreation'; |
| 31 | +
|
| 32 | + UPDATE public.utm_module_group_configuration |
| 33 | + SET conf_name = 'Change alert status after analysis', |
| 34 | + conf_description = 'If set to "true", SOC Ai will automatically change the status of alerts.' |
| 35 | + WHERE group_id = grp_id AND conf_key = 'utmstack.socai.changeAlertStatus'; |
| 36 | +
|
| 37 | + -- 4. Insert/Re-insert Provider Preset (Connection Section) |
| 38 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type, conf_options) |
| 39 | + VALUES (grp_id, 'utmstack.socai.provider', 'Provider Preset', 'Select your AI provider', 'openai', true, 'select', |
| 40 | + '[{"value": "openai", "label": "OpenAI"}, {"value": "anthropic", "label": "Anthropic"}, {"value": "azure", "label": "Azure OpenAI"}, {"value": "ollama", "label": "Ollama (Local)"}, {"value": "custom", "label": "Custom"}]') |
| 41 | + ON CONFLICT (group_id, conf_key) DO UPDATE SET conf_options = EXCLUDED.conf_options, conf_name = EXCLUDED.conf_name; |
| 42 | +
|
| 43 | + -- 5. Insert Connection Details |
| 44 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type) |
| 45 | + VALUES (grp_id, 'utmstack.socai.url', 'API URL', 'Auto-filled by preset (editable)', 'https://api.openai.com/v1/chat/completions', true, 'text') |
| 46 | + ON CONFLICT (group_id, conf_key) DO NOTHING; |
| 47 | +
|
| 48 | + -- Update existing model key |
| 49 | + UPDATE public.utm_module_group_configuration |
| 50 | + SET conf_name = 'Model', conf_description = 'Choose the AI model' |
| 51 | + WHERE group_id = grp_id AND conf_key = 'utmstack.socai.model'; |
| 52 | +
|
| 53 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type) |
| 54 | + VALUES (grp_id, 'utmstack.socai.maxTokens', 'Max Tokens', 'Required for Anthropic', '4096', false, 'number') |
| 55 | + ON CONFLICT (group_id, conf_key) DO NOTHING; |
| 56 | +
|
| 57 | + -- 6. Update Authentication (API Key mapping) |
| 58 | + UPDATE public.utm_module_group_configuration |
| 59 | + SET conf_name = 'API Key', |
| 60 | + conf_description = 'Authentication key for the provider', |
| 61 | + conf_visibility = '{"dependsOn": "utmstack.socai.provider", "values": ["openai", "anthropic", "azure"]}' |
| 62 | + WHERE group_id = grp_id AND conf_key = 'utmstack.socai.key'; |
| 63 | +
|
| 64 | + -- 7. Insert Custom Auth Fields (Visible only for Custom preset) |
| 65 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type, conf_options, conf_visibility) |
| 66 | + VALUES (grp_id, 'utmstack.socai.authType', 'Auth Type', 'Select authentication method', 'custom-headers', false, 'select', |
| 67 | + '[{"value": "custom-headers", "label": "Custom Headers"}, {"value": "none", "label": "None"}]', |
| 68 | + '{"dependsOn": "utmstack.socai.provider", "values": ["custom"]}') |
| 69 | + ON CONFLICT (group_id, conf_key) DO NOTHING; |
| 70 | +
|
| 71 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type, conf_visibility) |
| 72 | + VALUES (grp_id, 'utmstack.socai.customHeaders', 'Custom Headers', 'JSON format for custom headers (e.g. {"Authorization": "Bearer sk-xxx"})', '{}', false, 'text', |
| 73 | + '{"dependsOn": "utmstack.socai.provider", "values": ["custom"]}') |
| 74 | + ON CONFLICT (group_id, conf_key) DO NOTHING; |
| 75 | +
|
| 76 | + -- 8. Insert new behavior key |
| 77 | + INSERT INTO public.utm_module_group_configuration (group_id, conf_key, conf_name, conf_description, conf_value, conf_required, conf_data_type) |
| 78 | + VALUES (grp_id, 'utmstack.socai.autoAnalyze', 'Auto-analyze alerts', 'If enabled, the system will automatically send alerts for analysis.', 'true', false, 'bool') |
| 79 | + ON CONFLICT (group_id, conf_key) DO NOTHING; |
| 80 | +
|
| 81 | + END IF; |
| 82 | +end; |
| 83 | +$$ language plpgsql; |
| 84 | + ]]> |
| 85 | + </sql> |
| 86 | + </changeSet> |
| 87 | +</databaseChangeLog> |
0 commit comments