Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: use top-level JSONB paths in the SCIM token migration

Danny5e0c7e68d933
diff --git a/backend/migrator/migration/3.22/0003##hash_directory_sync_token.sql b/backend/migrator/migration/3.22/0003##hash_directory_sync_token.sql
index bb949b4a74..0343cb43ca 100644
--- a/backend/migrator/migration/3.22/0003##hash_directory_sync_token.sql
+++ b/backend/migrator/migration/3.22/0003##hash_directory_sync_token.sql
@@ -12,28 +12,27 @@
-- human-chosen secret, so key stretching buys nothing and would cost latency on
-- every SCIM request. sha256() is built into PostgreSQL 11+; no pgcrypto needed.
--
--- JSONB keys are protojson camelCase, hence directorySyncToken / *Hash.
+-- setting.value holds protojson of the setting message itself (UpsertSetting
+-- marshals SettingMessage.Value directly), so WorkspaceProfileSetting's fields
+-- are TOP-LEVEL camelCase keys. There is no "workspaceProfile" wrapper here —
+-- that wrapper only exists in the v1 API, where the setting is carried inside
+-- the SettingValue oneof.
-- 1. Hash any real token that does not already have one. Reads the plaintext
-- before step 2 removes it.
UPDATE setting
SET value = jsonb_set(
value,
- '{workspaceProfile,directorySyncTokenHash}',
- to_jsonb(
- encode(
- sha256(convert_to(value -> 'workspaceProfile' ->> 'directorySyncToken', 'UTF8')),
- 'hex'
- )
- )
+ '{directorySyncTokenHash}',
+ to_jsonb(encode(sha256(convert_to(value ->> 'directorySyncToken', 'UTF8')), 'hex'))
)
WHERE name = 'WORKSPACE_PROFILE'
- AND coalesce(value -> 'workspaceProfile' ->> 'directorySyncToken', '') <> ''
- AND NOT (value -> 'workspaceProfile' ? 'directorySyncTokenHash');
+ AND coalesce(value ->> 'directorySyncToken', '') <> ''
+ AND NOT (value ? 'directorySyncTokenHash');
-- 2. Drop the plaintext wherever it still appears, including the empty-string
-- rows step 1 skips and any row already carrying a hash.
UPDATE setting
-SET value = value #- '{workspaceProfile,directorySyncToken}'
+SET value = value - 'directorySyncToken'
WHERE name = 'WORKSPACE_PROFILE'
- AND value -> 'workspaceProfile' ? 'directorySyncToken';
+ AND value ? 'directorySyncToken';