Skip to content

feat(migrate): revision-chain ordering + struct-snapshot scaffolding#26

Merged
mlwelles merged 8 commits into
mainfrom
migration-scaffolding-and-chain-ordering
May 30, 2026
Merged

feat(migrate): revision-chain ordering + struct-snapshot scaffolding#26
mlwelles merged 8 commits into
mainfrom
migration-scaffolding-and-chain-ordering

Conversation

@mlwelles
Copy link
Copy Markdown
Owner

Summary

Adds Alembic-style explicit revision-chain ordering and struct-snapshot migration scaffolding to the migrate engine, migratecli, and modusgraph-gen.

Ordering — the revision chain

  • Migration.After names each migration's predecessor; exactly one root has After == 0. The runner walks the chain instead of sorting by ID, so it catches parallel-branch divergence a timestamp sort hides.
  • buildChain validates before any work and returns a typed error on the first fault: ErrDuplicateID, ErrNoRoot, ErrMultipleRoots, ErrUnknownPredecessor, ErrDivergentHistory, ErrCycle.
  • up/down/status now order by the chain. After is folded into the migration checksum (structural → immutable once applied).
  • migrate history [--tree] [--verbose] renders the chain, marks forks, and exits non-zero on a structural fault — a CI chain lint.

Scaffolding

  • modusgraph-gen emits schema.Models() []any (one zero value per entity), so tooling cannot fall out of sync with the declared types.
  • schema_state.schema is a checked-in, tool-managed desired-state snapshot.
  • diffSchema classifies each predicate change: Added/IndexChanged → emitted as an additive EnsureSchema delta; TypeChanged/Removed → flagged for RetypePredicate/explicit drop, never auto-applied.
  • Scaffold / Snapshot / Diff write the <id>_<name>.{go,schema} pair, advance the snapshot, and AST-append the new var to the All slice (best-effort). ResolveDir fails fast with actionable messages outside a project root.
  • Verify checks the live schema against the structs (one-directional); detects Missing everywhere and Mismatched against a real Dgraph.

CLI + docs

  • migratecli: create / diff [--check] / snapshot / verify commands; Provider gains Models(). diff --check and verify exit non-zero on drift.
  • New migrate/MIGRATIONS.md library guide + runnable Example* tests.

Testing

go build ./... && go test ./... — all packages pass.

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