Schema migration system for ZIO Schema 2#974
Conversation
|
Ahmed seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Pull request overview
This PR implements a pure, algebraic schema migration system for ZIO Schema 2 that represents structural transformations between schema versions as first-class, serializable data. The system provides type-safe migrations with compile-time validation, reversibility, and path-based error reporting.
Changes:
- Core migration types:
Migration[A,B],DynamicMigration,MigrationActionADT, andDynamicSchemaExprfor serializable value transformations - Structural schema derivation for Scala 3 (refinement types and union types) with runtime restrictions
- Type-safe selector macros and builder syntax for ergonomic path construction in both Scala 2 and 3
- Build-time validation via
MigrationValidatorand default value resolution inMigrationBuilder - Comprehensive test coverage (1600+ tests) across all migration operations
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| MigrationAction.scala | ADT defining 15+ migration actions (AddField, DropField, RenameField, etc.) with structural reversibility |
| DynamicMigration.scala | Untyped migration interpreter operating on DynamicValue with comprehensive path traversal |
| Migration.scala | Typed wrapper providing type-safe apply with error handling for structural schemas |
| DynamicSchemaExpr.scala | Serializable expression DSL supporting arithmetic, string ops, type coercion, and path navigation |
| MigrationBuilder.scala | Fluent builder API with strict/best-effort default value resolution at build time |
| MigrationValidator.scala | Structural validation by simulating actions and comparing schema structures |
| MigrationError.scala | Path-aware error types with detailed diagnostic messages |
| Selector.scala | Type-safe selector abstraction for composable paths |
| SelectorMacros.scala (2+3) | Compile-time conversion of lambda expressions to DynamicOptic paths |
| MigrationBuilderSyntax.scala (2+3) | Extension methods enabling selector syntax on MigrationBuilder |
| SchemaCompanionVersionSpecific.scala | Scala 3 structural derivation for refinement/union types; Scala 2 throws unsupported |
| Binding classes | StructuralConstructor/Deconstructor/Matcher that throw at runtime (compile-time only) |
| JsonBinaryCodecDeriver.scala | Delayed register initialization fix for recursive record encoding |
| Test utilities | Newline normalization for cross-platform test consistency |
| Test specs | 10+ comprehensive test files covering all actions, errors, validation, and serialization |
| MigrationSchemas.scala | Hand-written schemas for serializing migration types |
| docs/reference/migration.md | Complete API documentation with examples and best practices |
| package.scala | Package documentation describing key types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…calls - Replace typeName with typeId in structural derivation macros - Use TypeId.nominal for structural types - Fix DynamicValue.Record to use varargs or Chunk instead of Vector - Fix MigrationValidator to use typeId.name instead of typeName.name
- Fix scalafmt issues in Scala 2 and Scala 3 migration files - Fix Scaladoc @throws annotation to use fully qualified name - Add MigrationValidatorSpec with 44 comprehensive tests - Add 25+ error path tests to DynamicMigrationSpec - Total migration tests increased from ~94 to ~166
- Add error aggregation tests for AtIndices, AtMapKeys, Elements, MapKeys, MapValues - Add DynamicSchemaExpr tests: StringConcat, StringLength, CoercePrimitive, Arithmetic ops - Add Logical/Relational operator tests - Add navigateDynamicValue coverage tests - Add Wrapped, AtMapKey, Case path navigation edge case tests - Add MigrationValidator path navigation tests for all optic types - Increase branch coverage to meet 80% minimum requirement
|
Superseded by #982 |
Summary
Examples
Structural schema + addField
Selector grammar (paths)
MigrationBuilder[Old, New]
.dropField(.address.street)
.optionalizeField(.email)
.buildPartial
Notable behavior
Tests
Demo / Video
migration-demo.mp4
Notes / limitations
Review guide
Issues