pgdesign v0.26.0 /internal/project
On this page

Package project is the shared project-loading core, reconciling parsed schemas, config, and vendored imports into one resolved model and semtype registry.

#internal/project

#internal/project

Package project is the shared project-loading core: it reconciles a parsed schema set, the project's pgdesign.toml config, and the vendored import surface into ONE resolved model — the semtype registry (builtin + config [[extensions]] + user types + imported enums), the vendored import reference tables, and the config/toml pg_version tiers folded into schema.PGVersion.

It is the single reconciliation point shared by build, codegen, revise, and serve. Before this package, serve had its own loader that used the builtin registry only, applied no config extensions, resolved no pg_version, and loaded no import surface; routing every consumer through Build removes that drift.

Build takes ALREADY-PARSED raw schemas plus the loaded config and project root, so path resolution and TOML parsing stay a CLI-input concern in package main. It returns all diagnostics (errors, warnings, info) and never writes to stderr or exits — the caller decides how to render and gate.

#Project

Go go
type Project struct

Project is a fully resolved project: the built model, the semtype registry that produced it (registry-present type information), and the config it was built from. ProjectRoot is the directory holding pgdesign.toml (empty when no config root was resolved, which also disables import-surface loading).

#Build

Go go
func Build(raws []*parse.RawSchema, cfg *config.RawConfig, projectRoot string) (*Project, diagnostic.Diagnostics)

Build reconciles the parsed raw schemas into a resolved Project. It performs, in order: registry construction (builtin + config [[extensions]] types), user-type loading from every schema, vendored import-surface loading (when projectRoot is set and the config declares imports), owned/imported name-collision enforcement, the model build, and pg_version tier folding (config over toml). cfg may be nil (treated as an empty config); projectRoot "" skips import-surface loading.

On any hard error the returned Project is nil and diags carries the reason.

#ImportAliasSchemas

Go go
func ImportAliasSchemas(cfg *config.RawConfig) map[string]string

ImportAliasSchemas projects the project's [imports] declarations into the alias -> target-PG-schema map model.WithImports consumes, so alias:table FK references resolve at build time (roadmap 7.1). A nil config yields nil.

#RegisterImportedTypes

Go go
func RegisterImportedTypes(reg *semtype.Registry, surface *model.Schema) diagnostic.Diagnostics

RegisterImportedTypes enforces registry rules for the vendored import surface (roadmap 7.3): an imported type name that collides with a local (non-builtin) type is a hard error naming both sources (E243), and imported enums are registered so local columns can reference them. Collision detection covers every imported type kind; only enums are registered (the roadmap's "imported enums usable in local columns" — other imported types are referenced only through FK targets).

Search