Closes #519

/claim #519

Overview

This PR introduces a pure, algebraic migration engine for ZIO Schema 2. It represents structural transformations between schema versions as first-class, serializable data, bypassing runtime reflection and closure pollution.

By separating the user-facing typed Builder API (Migration[A, B]) from the untyped traversal execution engine (DynamicMigration), this architecture supports zero-overhead schema evolution with offline backward/forward serialization constraints perfectly intact.

Key Architecture & Features

1. Pure Data Actions (MigrationAction)

  • Full implementation of the MigrationAction ADT operating directly on DynamicOptic.
  • Algebraic structural reverses provided natively for all modifiers (e.g., AddField naturally structural-reverses to DropField).
  • Pure AST representations guarantee that these migration instructions can be serialized safely entirely without reflection or lambdas.

2. Stack-Safe Execution (DynamicMigration)

  • The internal schema traversal on DynamicValue is fully refactored onto a custom Trampoline interpreter.
  • Predictably evaluates heavily nested Sequences, Maps, and nested Schemas entirely safely without StackOverflowError risks.

3. Compile-Time Builder & Validation (MigrationBuilder)

  • Provided MigrationBuilder[A, B] for highly fluent migrations mapping structural identities (Enum operations, elements, and keys natively supported).
  • Macro validation engine (.build): Fully interprets both Scala 2.13 and Scala 3 AST logic, mapping .renameField(_.source, _.target) safely into DynamicOptic(Node.Field("...")).
  • Shape Diff Engine: Compares Source (A) and Target (B) case accessors at compile time via Quotes/Blackbox. Any new fields in the target that are not covered by an action (AddField, Rename) trigger a direct compilation abort cleanly guiding the developer.
  • Provided .buildPartial as an escape hatch.

4. Tests & Documentation

  • Comprehensive tests injected at MigrationSpec.scala testing standard data preservation mapped back to Migration.identity, as well as sequential associativity limits (m1 ++ m2).
  • Generated an end-to-end MIGRATION_GUIDE.md to establish user onboarding and document macro-error expectations natively for the toolkit.

Verification

  • Environment compiled cleanly on Scala 2.13.12 and Scala 3.7.4.
  • Extractor macros safely evaluate block, inlining, and application layers spanning across the builder chains to correctly isolate invocation elements.

Claim

Total prize pool $8,000
Total paid $0
Status Pending
Submitted March 26, 2026
Last updated March 26, 2026

Contributors

MO

Mohit Jeswani

@mohitjeswani01

100%

Sponsors

MA

marianaguzmanguerrero16-dev

@marianaguzmanguerrero16-dev

$4,000
ZI

ZIO

@ZIO

$4,000