Skip to content

feat: improve api for migration registration#33

Merged
subomi merged 4 commits intomainfrom
subomi/feat/cleanup
Feb 20, 2026
Merged

feat: improve api for migration registration#33
subomi merged 4 commits intomainfrom
subomi/feat/cleanup

Conversation

@subomi
Copy link
Copy Markdown
Owner

@subomi subomi commented Feb 20, 2026

Summary

This PR refines migration registration into an explicit build lifecycle and tightens runtime behavior.

  • Introduces a fluent registration API: rm.Register(Migration[T](...)).Build().
  • Moves eager graph creation to Build() (instead of registration-time side effects).
  • Streams typed <-> generic JSON conversion via io.Pipe helpers to avoid extra full-buffer allocations.

Breaking API changes

  • Replaces the standalone Register[T](rm, version, migration) error flow with:
    • Migration[T](version, migration)
    • (*RequestMigration).Register(...VersionedTypeMigration) *RequestMigration
    • (*RequestMigration).Build() error
  • For/Bind now require a prior Build() call and return ErrNotBuilt if called early.
  • Registering more migrations after build now returns ErrAlreadyBuilt.

Behavior updates

  • Build() now:
    • validates accumulated registration state,
    • sorts versions by configured format,
    • eagerly builds/caches type graphs for registered types,
    • marks the migrator immutable for request-time usage.
  • Runtime lazy graph fallback remains for unregistered container/interface-driven shapes.

Test plan

  • Updated existing tests to the new Register/Build lifecycle.
  • Added/updated coverage for build-gating (ErrNotBuilt) and eager cache-at-build expectations.
  • go test ./...

@subomi subomi merged commit f34b2ff into main Feb 20, 2026
6 checks passed
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.

1 participant