Skip to content

sql/no-client-schema is generated but never compiled #5

Description

@lesomnus

Corrected. The first version of this said nothing in the repository
generates with the flag on. That is wrong: entc/gen/graph_test.go builds a
graph with Features: AllFeatures, and #4 appended FeatureNoClientSchema to
that list, so TestGraph_Gen renders the flag-on templates on every
go test ./entc/gen/. The gap is narrower than stated and is below.

sql/no-client-schema (#4) drops Client.Schema and the <pkg>/migrate import
with it, so a binary that never migrates does not link Atlas.

What is covered

TestGraph_Gen runs graph.Gen() with every feature on, so the flag-on branch
of client.tmpl and enttest.tmpl is rendered, and Gen runs imports.Process
over the result (entc/gen/graph.go:1167). A template that fails to execute, or
that produces Go which does not parse, fails the test.

What is not

That test only os.Stats the files it expects. Nothing compiles them.

  • A type error passes. enttest.tmpl renders migrate.NewSchema(c.Driver())
    under this flag; if Client.Driver() were renamed or its signature changed,
    the file would render, parse and format, and every job would stay green.
  • A stale import passes silently, because imports.Process removes it rather
    than reporting it.

The generate job compiles nothing extra either — every package in this
repository is generated with the flag off, which is what that job pins.

What would close it

A small integration package generated with the flag on, alongside the ones
generated without it: a schema, a generate.go carrying the feature, and a test
that creates the schema the way a caller must under this flag.

if err := migrate.NewSchema(drv).Create(ctx); err != nil {
	...
}

Then both paths are compiled on every run and the generate job holds them both.

Also

entc/gen/template/migrate/migrate.tmpl:70 documents client.Schema.WriteTo in
a comment. Under this flag there is no client.Schema, so the example in the
generated package names something that package does not have.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions