gen: a feature-flag that keeps the migration engine off Client - #4
Conversation
`Client.Schema` is a `*migrate.Schema` and `NewClient` builds one, which is an import, and the linker follows imports: a generated package pulls in `dialect/sql/schema`, which pulls in Atlas -- its diff planner, all three SQL dialects, and the HCL parser those import for a schema language most programs never write. A program that never migrates carries all of it. Measured on an app compiled to `GOOS=js GOARCH=wasm` and served from its own page: 10.5 MB of a 56.9 MB module, linked to answer a question the program does not ask. `sql/no-client-schema` drops the field and its init. The caller says it instead, with the driver it already had to build the client: migrate.NewSchema(drv).Create(ctx) Off by default, so every generated client in this repository is unchanged -- checked: with the flag off, generation is byte-identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbzZbDZvDr4DCiEamJf585
|
Reviewed and verified locally against master (which now carries the CI fixes this PR's red run was waiting on — the lint job could not load its config on Go 1.27, and What I checked, rather than took from the description:
Three guard points and all three are covered: the field, its init, and the import. Experimental and off by default, so nothing that does not ask for it can be affected. One gap, filed as #5 rather than held against this: nothing in this repository generates with the flag on, so a later template change could break the flag path and no test would say so. That is the exact shape of several things found in this repository today — a view definition, a migration directory, eight examples — each wrong for as long as nothing ran it. |
ClientholdsSchema *migrate.SchemaandNewClientbuilds one. That is an import, and the linker follows imports: a generated package pulls indialect/sql/schema, which pulls in Atlas — its diff planner, all three of its SQL dialects, and the HCL parser those import for a schema language most programs never write.A program that never migrates carries all of it anyway.
Measured on an app compiled to
GOOS=js GOARCH=wasmand served from the page it serves, where the database is created once from a script and never migrated:10.5 MB of a 57 MB module, gzip 10.9 MB → 8.77 MB, linked to answer a question the program does not ask. Atlas, HCL and cty symbols go from present to zero.
What it does
sql/no-client-schemadrops theSchemafield and its init. The caller says it instead, with the driver it already had to build the client:migrateis generated either way, soTablesand versioned migrations are unaffected — this is only about whatClientcarries.Off by default
Every generated client in this repository is unchanged, and that is checked rather than asserted:
go generate ./idtype/ent/underentc/integrationwith the flag off rewrites no.gofile at all.enttestis conditioned the same way, so its output is byte-identical too.Checked
go build ./...— exit 0go test ./entc/gen/...— exit 0🤖 Generated with Claude Code
https://claude.ai/code/session_01UbzZbDZvDr4DCiEamJf585