Implement schema-driven type coercion for profile data to handle schema evolution without bulk updates #140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
When identity attribute schemas sync from WSO2 Identity Server to CDS, schema changes (type modifications, attribute removal, new attributes) previously required expensive bulk profile updates. This becomes operationally infeasible at scale.
Goals
Enable schema evolution without bulk profile rewrites by applying type coercion at read time based on the current schema definition.
Approach
Core Implementation
Type Coercion Layer (
internal/system/utils/type_coercion.go)CoerceValueToType()- Runtime type conversion supporting: string, integer, decimal, boolean, datetime, complexApplySchemaToAttributes()- Batch coercion across attribute mapsProfile Service Integration (
internal/profile/service/profile_service.go)buildSchemaMap()- Converts ProfileSchema to O(1) lookup structureapplySchemaToProfile()- Applies coercion to identity_attributes, traits, application_dataGetProfile(),GetAllProfiles(),GetAllProfilesWithFilter()Coercion Rules
Example
Design Rationale
User stories
Release note
Schema-driven type coercion enables seamless schema evolution. Profile attribute values are now automatically coerced to match the current schema at read time, eliminating the need for bulk profile updates when schemas change.
Documentation
N/A - Internal implementation pattern. No user-facing API changes. Existing profile CRUD operations work identically; coercion is transparent.
Training
N/A - No changes to user workflows or APIs.
Certification
N/A - Internal implementation enhancement with no changes to product behavior or features requiring certification content.
Marketing
N/A - Infrastructure improvement with no customer-facing feature changes.
Automation tests
Unit tests
Integration tests
test/integration/schema_evolution_test.goSecurity checks
Samples
N/A - Internal implementation with no sample code required.
Related PRs
None
Migrations (if applicable)
N/A - No database schema changes. Existing profiles work immediately with new schema versions.
Test environment
Learning
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.