textmachine/platform/sqlc.yaml

62 lines
3.5 KiB
YAML

# sqlc: the SQL of the glue-free block of `internal/pgstore` is written in .sql files and the Go that
# runs it is GENERATED, so that a statement's `$n` arity and its `Scan` targets cannot disagree with
# the statement itself. That disagreement is a class the standing gate cannot see:
# `TestEverySQLStatementParsesAgainstTheMigratedSchema` hands Postgres the final SQL string and never
# looks at the Go side of the call, so a swapped pair of same-typed Scan targets plans perfectly and
# returns wrong values. Six such mutations were planted in this package and ALL SIX survived the full
# battery; the ones this file exists to prevent are recorded in
# `docs/archive/platform-PROGRESS-P9-P13.md` (the `sqlc` pack).
#
# ⚠ It covers the glue-free block ONLY, and that is by construction rather than by preference: sqlc
# sees SQL written as one whole literal, and two thirds of this package's statements are assembled
# from shared fragments. Those keep their hand-written form and their own gate.
version: "2"
sql:
- engine: postgresql
# The SAME directory the integrity manifest `migrations.sha256` already gates. A copy of the
# schema in this file would be a second carrier of a fact that manifest cannot see, and the two
# would drift in the direction nobody is watching. sqlc reads goose's own annotations.
schema: internal/pgstore/migrations
queries: internal/pgstore/queries
gen:
go:
package: pgstore
# Generated INTO the package, not into a sub-package. Two reasons, both measured: the SQL
# gate globs `*.go` in its OWN directory, so generated statements fall under it for free (the
# count went 173 -> 174 the moment the first one landed, and Postgres planned it); and the
# gate's floor of 140 statements is a check on the extractor itself, so moving these 41 call
# sites out of its reach would turn it red on its own floor.
out: internal/pgstore
sql_package: pgx/v5
omit_unused_structs: true
overrides:
# Money is whole micro-dollars and must not become a float on any step (class PD-15).
# Written as a WILDCARD rather than nine column entries so that a money column in a table
# that does not exist yet is integral by default: the failure mode of a list is that
# somebody adds the tenth column and not the tenth line. Without this, sqlc emits int64.
- column: "*.*_micro_usd"
go_type: "textmachine/platform/internal/money.MicroUSD"
# The package speaks time.Time at its boundary; pgtype.Timestamptz would be a new type in
# every signature it touches, for nothing.
- db_type: "timestamptz"
go_type: "time.Time"
- db_type: "timestamptz"
nullable: true
go_type:
type: "time.Time"
pointer: true
# A nullable integer is a pointer here too, for the same reason: pgtype.Int4 would put a
# driver type in a domain signature, and "absent" is already spelled nil everywhere else in
# this package.
- db_type: "pg_catalog.int4"
nullable: true
go_type:
type: "int32"
pointer: true
# Same reasoning for a nullable address: "" and "no address" are different facts here (see
# `nullable` in identity.go), and nil is how the package already spells the second.
- db_type: "text"
nullable: true
go_type:
type: "string"
pointer: true