Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
zdevaty committed Jun 27, 2024
1 parent d5e76be commit 29543c8
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions conf/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,58 @@ CREATE TABLE IF NOT EXISTS saml_sp.permissions (
language_map JSON , -- e.g. {"Sprache:Deutsch":"de", "Sprache:Englisch":"en"}
CONSTRAINT chk_language CHECK (default_language IN ('en', 'de', 'it', 'fr'))
) ;

DO $$
BEGIN
-- Check if the adfs schema exists
IF EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'adfs') THEN
-- Migrate data from the existing adfs.config table to the new saml_sp.config table
INSERT INTO saml_sp.config (id, enable, sp_certificate, sp_private_key, idp_metadata_url, own_url, user_to_archive, allow_initialization_by_idp, signed_request, force_authn, entity_id, login_failed_url)
SELECT
1 AS id,
enabled AS enable,
cert AS sp_certificate,
key AS sp_private_key,
metadata_url,
own_url,
false AS user_to_archive,
false AS allow_initialization_by_idp,
true AS signed_request,
false AS force_authn,
own_url || '/apps-public/saml-sso/saml/metadata' AS entity_id,
COALESCE(redirect_on_fail_url, own_url || '/noLogin') AS login_failed_url
FROM adfs.config
WHERE config_id = 1
ON CONFLICT (id)
DO NOTHING;

-- Migrate data from the existing adfs.attribute_map table to the new saml_sp.attribute_map table
INSERT INTO saml_sp.attribute_map (id, email, first_name, last_name, phone)
SELECT
1 AS id,
email,
first_name,
last_name,
phone
FROM adfs.attribute_map
ON CONFLICT (id)
DO NOTHING;

-- Migrate additional attribute mappings to the saml_sp.permissions table
INSERT INTO saml_sp.permissions (id, default_system_role, default_proj_role, default_language, system_role_saml_attribute, system_role_map, proj_role_saml_attribute, proj_role_map, language_saml_attribute, language_map)
SELECT
1 AS id,
default_system_role,
default_project_role,
default_language,
system_role_attr,
system_role_attr_map,
project_role_attr,
project_role_attr_map,
language_attr,
language_attr_map
FROM adfs.attribute_map
ON CONFLICT (id)
DO NOTHING;
END IF;
END $$;

0 comments on commit 29543c8

Please sign in to comment.