feat(schema): Implement Algebraic Schema Migration System#1221
Open
DakodaStemen wants to merge 3 commits intozio:mainfrom
Open
feat(schema): Implement Algebraic Schema Migration System#1221DakodaStemen wants to merge 3 commits intozio:mainfrom
DakodaStemen wants to merge 3 commits intozio:mainfrom
Conversation
12 tasks
3788110 to
f881ace
Compare
f881ace to
aa80d18
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #519
/claim #519
Summary
This PR implements a pure, algebraic schema migration system for ZIO Blocks. The architecture shifts
migration validation from runtime to compile time, ensuring mathematically sound shape equivalence
between schema versions.
Architecture
Pure data core. Migrations are modelled as a
MigrationActionADT — no closures, opaque functions,or reflection. Every migration is fully serialisable.
Selector macro API. Custom macros for Scala 2.13 (
scala-reflect) and Scala 3 (scala.quoted)extract
S => Aselector lambdas intoDynamicOpticpaths at compile time. The developer-facing API isidentical across both versions:
Two-layer design.
DynamicMigration— untyped, serialisable core operating onDynamicValueMigration[A, B]— typed façade with Schema-driven encode/decodeCompile-Time Validation
The
.buildmacro performs a symbolic dry-run of the builder AST against structuralRefinementtypes,proving shape equivalence at compile time. A missing or misaligned field is a compiler error, not a
runtime failure. Structural types (e.g.
type PersonV0 = { def firstName: String }) are nativelysupported for past schema versions without requiring concrete case classes.
Cross-version AST stability is maintained across Scala 3.3.x and 3.7.x — the
SelectorMacrointerceptsboth
IdentandSelectpatterns arising fromreflectiveSelectableFromLangReflectiveCallsdesugaring.End-to-end proof is in
jvm/src/test/scala-3/.../StructuralTypeMigrationSpec.scala.Algebraic Laws
MigrationLawsSpecverifies the following invariants via property-based testing:empty.apply(v) == Right(v)for any Record or Variant(m1 ++ m2) ++ m3andm1 ++ (m2 ++ m3)produce identical resultsm.reverse.reverse.actions.length == m.actions.length; round-trips recover theoriginal value for all invertible operations
44 tests pass across Scala 2.13, 3.3, and 3.7 on both JVM and JS targets.
zio-519-demo.mp4