Skip to content

feat(schema): implement purely algebraic schema migration system#1241

Open
Abhishek9639 wants to merge 1 commit intozio:mainfrom
Abhishek9639:Abhishek
Open

feat(schema): implement purely algebraic schema migration system#1241
Abhishek9639 wants to merge 1 commit intozio:mainfrom
Abhishek9639:Abhishek

Conversation

@Abhishek9639
Copy link

Closes #519
/claim #519

Greeting @jdegoes,

Here’s my implementation of the purely algebraic Schema Migration System. I focused on building a reliable, serializable, and reversible system for handling structural schema transformations.

Overview of the Approach

  1. Core Data Layer (Untyped & Serializable)
  • I introduced MigrationError to provide clear error messages with proper path tracing.
  • Implemented MigrationAction, which covers all 14 required path based transformations (using DynamicOptic). Each action also supports a structural reverse operation.
  • Built DynamicMigration as the core engine that ties everything together. It follows important properties like identity, associativity, and reversibility.
  1. Typed API for Users
  • Created Migration[A, B] to safely handle transformations from one type to another (A → DynamicValue → B) using schemas.
  • Added a MigrationBuilder to collect and apply actions. For now, it works directly with DynamicOptic.

Design Decisions

As mentioned in the issue, I’ve intentionally deferred macro-based selectors (like _.address.street).
Supporting macros that work properly across both Scala 2.13 and Scala 3 is quite complex and deserves its own focused effort. Instead, I prioritized building a solid and fully serializable foundation first (DynamicMigration + DynamicOptic).
This ensures we have a strong core system in place, and it will be easier to add macro based syntax on top later.

Testing & Validation

  • Added around 70 test cases across:
    • MigrationActionSpec
    • DynamicMigrationSpec
    • MigrationSpec
  • Verified key properties like identity, associativity, and reversibility
  • Confirmed that the code works on both Scala 2.13 and Scala 3.7+

@CLAassistant
Copy link

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

@Abhishek9639 Abhishek9639 force-pushed the Abhishek branch 2 times, most recently from deeebfc to 0c643f3 Compare March 19, 2026 15:18
@Abhishek9639
Copy link
Author

Greeting @jdegoes,
I’ve completed the implementation for the schema migration system and ensured all tests are passing successfully. I’ve also added detailed test coverage (70 test cases) to validate different migration scenarios. Whenever you get some time, could you please review this PR? I’d really appreciate your feedback, and I’m happy to make any required changes. Thanks

all.test.passed.mp4

…#519)

Implemented a purely algebraic migration system representing schema transformations as first-class, serializable data structures.
* Created MigrationAction for 14 actions utilizing DynamicOptic
* Implemented DynamicMigration and typed Migration[A, B] wrapper
* Added comprehensive ZIO tests for laws and behaviors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema Migration System for ZIO Schema 2

2 participants