Skip to content

Conversation

@BenraouaneSoufiane
Copy link

Hello team, this closes #519
Built on the following PRs (that already considered to be merged):

My edit/files changes are only:

zio-blocks/schema/shared/src/main/scala/zio/blocks/schema

  • SchemaExpr.scala

zio-blocks/schema/shared/src/main/scala/zio/blocks/schema/migration

  • DynamicMigration.scala
  • DynamicMigrationInterpreter.scala
  • Migration.scala
  • MigrationError.scala
  • MigrationRegistry.scala
  • MigrationSchemaExpr.scala

zio-blocks/schema/shared/src/main/scala3/zio/blocks/schema/migration

  • MigrationBuilder.scala
  • MigrationValidator.scala

zio-blocks/schema/shared/src/test/migration

  • DynamicMigrationInterpreterSpec.scala
  • DynamicMigrationLawsSpec.scala
  • MigrationErrorSpec.scala
  • MigrationRegistrySpec.scala
  • MigrationSpec.scala

987Nabil and others added 28 commits January 7, 2026 12:35
…chema-migration

The issue 519 depends on issue 517 (that this pr resolves)
…tion

This issue zio#519 appears to share core prerequisites with zio#516 (DynamicValue + DynamicOptic path-based operations + macro/selector extraction).
…ma-migration" as not relevant

This reverts commit 1593848, reversing
changes made to 148d6b1.
- switch to DynamicMigration(Vector[MigrationAction]) core
- refactor interpreter to execute ordered actions
- introduce SchemaExpr-based defaults (DefaultValueExpr)
- thread source/target schemas through execution
- add selector-based DSL ops (rename/add/drop field)
- clean up registry and id usage
- fix selector-based DSL ops
- extend migration action algebra
- expand interpreter support and schema threading
- evaluate SchemaExpr via evalDynamic with proper inputs
- add build/buildPartial split and validation hooks
- add migration law test scaffolding
…aligning with zio#519

- Embed defaults as evaluatable SchemaExpr (MigrationSchemaExpr.DefaultValue) instead of DefaultValueExpr marker
- Remove runtime schema plumbing (sourceSchema/targetSchema, defaultForField) from DynamicMigrationInterpreter
- Simplify SchemaExpr evaluation (drop defaultProvider + DefaultValueExpr special-casing)
- Make Mandate/Optionalize reversible without inventing defaults by carrying default expressions explicitly
- Adjust AddField/DropField reverses to preserve default expressions for round-trip reversibility
- Update nested interpreter calls to use schema-free DynamicMigrationInterpreter(m, value)
- Keep schemas in typed Migration[A, B] for encode/decode only; dynamic core remains pure and introspectable
- General cleanups / minor interpreter correctness fixes (e.g., RenameCase payload preservation)
zio#519

Refactor the migration subsystem to match the zio#519 design:
make the core ADT, macro-based DSL, interpreter, and validator consistent,
pure, and selector-driven (DynamicOptic + SchemaExpr only).

- Align MigrationAction ADT with zio#519 (remove legacy actions, duplicates, and parent+field shapes)
- Update MigrationDsl macros to emit real actions using field optics (Rename, AddField, DropField)
- Extend DynamicMigrationInterpreter.modifyAt to support traversal optics
        (.each / Elements, .when[Case], mapKeys, mapValues)
- Ensure DefaultValue is schema-backed and captured at macro time for reversible migrations
- Add structural validation for migration actions (field paths, case selectors, empty joins/splits)

This brings migrations to a pure-data, selector-first model that is
serializable, reversible (where possible), and compatible with advanced selectors.
…Type; improve DSL/validation

Make DefaultValue a pure marker (MigrationSchemaExpr.DefaultValue) and resolve it in the interpreter via target schema defaults (no Schema captured in migration programs)

Thread sourceSchema + targetSchema through Migration.apply -> DynamicMigrationInterpreter to support default resolution and better runtime checks

Implement Join, Split, and ChangeType in DynamicMigrationInterpreter and enforce primitive→primitive constraints for these operations

Fix Rename.reverse to be structurally invertible by swapping field names and rebuilding the optic path

Expand typed MigrationDsl with missing builder ops: transformField, mandateField, optionalizeField, changeFieldType, joinFields, splitField, renameCase, transformCase

Fix dropField macro to stop referencing a non-existing helper and use DefaultValue marker for reverse

Upgrade MigrationValidator to catch common invalid programs early (field-path shape checks, join/split empties, case selector requirements)
…e API with zio#519

- Capture field-level schema defaults in macros instead of resolving defaults at runtime
- Replace stub migration validation with schema-based DynamicOptic path checks
- Ensure build validates migrations while buildPartial skips validation
- Expose DynamicMigration.apply for direct DynamicValue execution
- Keep migration programs pure, reversible, and interpreter-driven
- Ensured actions continue at the renamed field path
- Added .each and .when[Case] selector support
- Enabled correctly scoped enum/case migrations
- Makes MigrationBuilder exist on Scala 2 only to fail clearly, not silently.
… MigrationBuilderMacros of scala-3 into separated file
@BenraouaneSoufiane
Copy link
Author

I expected CI will pass after implementation+test successfully compiled locally, will reopen once fix CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema Migration System for ZIO Schema 2

3 participants