Skip to content

feat: interpret migrations with yaegi instead of compiling#2

Merged
ocomsoft merged 1 commit into
mainfrom
claude/use-yaegi-instead-compile-09rru
May 5, 2026
Merged

feat: interpret migrations with yaegi instead of compiling#2
ocomsoft merged 1 commit into
mainfrom
claude/use-yaegi-instead-compile-09rru

Conversation

@ocomsoft
Copy link
Copy Markdown
Owner

@ocomsoft ocomsoft commented May 5, 2026

Replace the build-and-fork approach with in-process yaegi interpretation:

  • cmd/migrate now loads migrations/*.go via yaegi and runs the embedded migrate.App directly — no go build, no temp binary, no GOWORK synthesis, no toolchain version dance.
  • cmd/go_migrations queryDAG calls BuildGraph + ToDAGOutput in-process on a freshly-loaded *migrate.Registry instead of round-tripping dag --format json through a child binary.
  • internal/interp/loader.go owns the loader: it rewrites each migration file's package main to a virtual package, places the files in an in-memory FS, and overrides migrate.Register with a per-call shim so multiple loads can coexist in one process.
  • migrate/symbols/ holds the yaegi symbol map (yaegi extract-generated for the migrate package) plus a Register() hook so users with third-party imports in their migrations can extend it.
  • cmd/drivers.go blank-imports github.com/mattn/go-sqlite3 in the CLI itself; previously users registered drivers via their own migrations/main.go, but with yaegi the host process is what runs SQL.

The migrations/ directory remains a buildable Go module so IDE tooling keeps working and a standalone binary is still an option for users who want one. Removed the now-dead helpers buildMigrationsBinary, findLocalMakemigrations, upgradeMakemigrationsVersion, isFullGoVersion (~250 lines of build-toolchain plumbing).

https://claude.ai/code/session_014Wn4chfaL2aTyjxMXeNBmm

…mpiled)

Reframe the documentation to make the runtime model explicit:
- Migration files are valid Go source — IDE/gopls/go vet treat them as
  ordinary Go and type-check them via migrations/go.mod.
- At runtime they are interpreted by yaegi (an embedded Go interpreter),
  not compiled by gc. The dialect is "Go-like": yaegi implements the Go
  spec but cgo, deep reflection, and some generics edge cases differ.
- migrations/main.go is now an *optional* standalone-binary fallback,
  not the primary execution path.

Touched files:
- README.md: prominent runtime-model callout in the lede; reword
  feature bullets to reflect "no build step at runtime" and "optional
  standalone binary".
- docs/architecture.md: rewrite the runtime sections, the data flow
  diagrams, the "Compiled Binary as Source of Truth" decision, the
  init() registration pattern, the App description, and the directory
  tree to reflect the in-process yaegi loader. Add a "yaegi Symbol Map"
  section pointing at migrate/symbols/.
- docs/migrations.md: add a runtime-model callout next to the writing
  guide so authors understand what runs their code; replace the
  remaining `cd migrations && go build` invocation in showsql with
  `makemigrations migrate showsql`.
- docs/Usage.md: rewrite the migrate intro and showsql section.
- docs/installation.md: add a "How migrations run" section, remove the
  Build the Migrations Binary step from the quickstart, and update the
  CGO troubleshooting guidance.
- docs/commands/init.md: explain main.go is optional and describe what
  go.mod and main.go are each for; replace the "Rebuild After Changes"
  section with "No Rebuild Step Required".
- docs/commands/makemigrations.md: explain the queryDAG step uses
  yaegi rather than go build; rewrite all example workflows to use
  `makemigrations migrate up`; rewrite the troubleshooting entry for
  load failures.
- docs/manual-migration-build.md: reframe the whole guide as the
  *optional* standalone-binary path with reasons you might want it,
  and lead the CI/CD example with the yaegi-based recommendation.
- docs/commands/db-diff.md: update the "what it does" step that still
  referred to running the compiled binary.

https://claude.ai/code/session_014Wn4chfaL2aTyjxMXeNBmm
@ocomsoft ocomsoft merged commit 1221f0f into main May 5, 2026
1 of 3 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.

2 participants