schemasource

package
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package schemasource maps a schema INPUT to the concrete parser that can read it. It is the single production site of that mapping (spec R11): the site may move, it must not multiply, because a second mapping site is how one caller starts reading a schema under a different parser than the one the audit uses.

It lives outside internal/core deliberately. The mapping names concrete providers (sqlddl, typescript), and "el núcleo NUNCA importa un provider concreto" — so a package that must name them cannot be a core package. It also lives outside internal/mcp, where it used to live, because the mapping is not a transport concern: `codefit init` needs the same binding the MCP scan uses, and a transport adapter handing a parser to a scaffolder was the seam showing.

The mapping resolves by the shape of the INPUT, never by the app language: a schema is orthogonal to the backend that talks to it (ADR 0018).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParserForPaths

func ParserForPaths(root string, paths []string, dbType string) (providers.SchemaParser, string)

ParserForPaths resolves the schema parser by the INPUT's shape, not by the backend language (a schema is orthogonal to the app language — PlantaLinda is Java with SQL-DDL migrations; ADR 0018). .prisma → the TS provider's parser; .sql (or a directory of migrations) → the SQL-DDL parser, bound to the SQL DIALECT named by dbType (design §4/§5) — mysql/postgresql/sqlserver select the matching sqlddl.Dialect descriptor; sqlite is an EXPLICIT not-yet-supported note (never a silent PostgreSQL parse, RF-03.6); ""/"none" keeps today's default (Postgres-parsed by-input resolution) — the heuristic sniff fallback (design's Unit J) is NOT YET IMPLEMENTED, so this deliberately does not pretend to sniff. A project mixing .prisma and .sql is a declared out-of-scope limit for this slice. Returns a note when no parser applies.

This package is the single place that maps input+dbType → concrete parser (spec R11), and TestSQLDDLHasExactlyOneProductionImporter holds it to that as a COUNT rather than a location. It used to be the MCP adapter, which was only ever true while the MCP scan was the sole caller; `codefit init` needs the same binding, and a transport adapter handing a parser to a scaffolder was the seam showing.

Types

type Proof

type Proof struct {
	// Ordered reports db.OrderingIsProven for this directory's own level: the
	// apply order comes from integer versions rather than from the alphabet.
	Ordered bool
	// SQLFiles counts the .sql files at the directory's own level.
	SQLFiles int
	// Tables is the number of tables the real parser reconstructed. It is the
	// only number that may promote a candidate to a live schema_paths entry.
	Tables int
	// Note carries the parser-binding note when no parser applied to this path.
	Note string
}

Proof is the measured account of one candidate directory: whether its apply order is proven, how many .sql files sit at its own level, how many tables the REAL parser reconstructed from it, and — when no parser applied — why.

Every field is a measurement. Nothing here is prose about a project: the wording that reaches a developer is internal/scaffold's job, and keeping it out of this package is what stops a reason sentence from drifting away from the number it explains.

func Prove

func Prove(root, relDir string) (Proof, error)

Prove answers the one question `codefit init` is allowed to answer before it writes a database block: does this directory RECONSTRUCT into a schema?

It never guesses. The chain is the scan-time chain, in scan-time order:

db.OrderingIsProven   — the ^V(\d+)__ shape gate, beside the regex that owns it
db.ResolveSchemaPath  — the literal scan-time reader: Flyway ordering + BOM decode
ParserForPaths(root, []string{relDir}, "")
                      — the SAME binding scandb.go makes when database.type is unset
ParseSchema           — the real parser, over the real bytes

Running the scan-time binding is the point, not a convenience. If init proved a path against its own reader, init-time proof and scan-time behaviour could disagree about the same directory, and the config would promise a schema the audit never reads. What remains is a declared residual: the DIALECT may be wrong (codefit does not sniff it), never that init and the scan read different schemas. Callers must state that residual where the developer can see it.

An unordered directory short-circuits: its files are not read and no parser runs, because a directory whose apply order is a fact about the alphabet cannot be proven by parsing it in that order.

relDir is project-relative and slash-spelled, exactly as it would be written into database.schema_paths.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL