Replace compiled migrations binary with in-process yaegi interpreter#1
Merged
Merged
Conversation
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
- cmd/drivers.go: blank-import github.com/go-sql-driver/mysql and github.com/microsoft/go-mssqldb so `makemigrations migrate` works out of the box for all four supported database types (postgres was already covered transitively via internal/providers/postgresql). - docs/extending-yaegi-symbols.md: explain the wrapper-CLI pattern for users whose hand-edited migrations import third-party packages not in the default symbol map. Covers both the recommended path (mmsymbols.Register from a generated `yaegi extract` file in a thin main wrapper) and the standalone-binary fallback. - README: link the new guide. https://claude.ai/code/session_014Wn4chfaL2aTyjxMXeNBmm
makemigrations migrate runs migration files in-process via yaegi and never invokes main(). The generated main.go remains as an optional escape hatch for users who want to `go build` the migrations directory into a standalone binary. The new file-level comment makes that explicit so users know the file is safe to delete (without losing IDE type-checking, which goes through go.mod). https://claude.ai/code/session_014Wn4chfaL2aTyjxMXeNBmm
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
| // package, dedupes imports, and runs all init() funcs in source order. | ||
| fsys := fstest.MapFS{} | ||
| for _, path := range migFiles { | ||
| data, readErr := os.ReadFile(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR eliminates the need to compile the migrations module into a temporary binary. Instead,
makemigrations migratenow loads and interprets migration.gofiles in-process using the yaegi Go interpreter, removing the Go toolchain requirement at runtime.Key Changes
Removed binary compilation pipeline: Deleted
buildMigrationsBinary()and all supporting functions (upgradeMakemigrationsVersion(),findLocalMakemigrations(),findParentGoVersion(),isFullGoVersion(),stderrSupportsColor(),warnf()) that managed temporary builds, workspace setup, and version upgrades.New in-process interpreter: Added
internal/interp/loader.gowithLoadRegistry()that:.gofiles (excludingmain.goand*_test.go)maintomigrations(yaegi cannot importmainpackages)migrate.Register()calls to populate a fresh*migrate.Registryper loadSimplified
queryDAG()andExecuteMigrate(): Both now callinterp.LoadRegistry()directly, build the migration graph, and invoke operations in-process instead of spawning external processes.Symbol map infrastructure: Added
migrate/symbols/package with:symbols.go: PublicRegister()API for extending the yaegi symbol map with third-party packagesmigrate.go: Auto-generated symbol map for themigratepackage (viayaegi extract)Updated documentation:
docs/extending-yaegi-symbols.mdguide for adding third-party packages to interpreted migrationsdocs/commands/migrate.mdto reflect in-process executionDriver registration: Added
cmd/drivers.goto blank-import SQL drivers (mysql,sqlserver,sqlite3) since migrations now run in the CLI's process rather than a standalone binary.Removed CLI flags:
--verboseand--dont-upgradeflags are no longer needed (no build step, no version management).Updated dependencies: Added
github.com/traefik/yaegi v0.16.1and SQL drivers togo.mod; bumped Go version to 1.25.7.Implementation Details
migrations) while preserving all comments and formatting viago/astandgo/printer.perLoadSymbols()function clones the global symbol map and overridesmigrate.Registerto write into a per-load registry, enabling isolation.internal/interp/loader_test.goverify correct loading, empty directory handling, and isolation between consecutive loads.migrations/main.goremains optional for backward compatibility (users can stillgo buildstandalone if desired).https://claude.ai/code/session_014Wn4chfaL2aTyjxMXeNBmm