Skip to content

fix: keep configured schema order; strict env and duration checks - #92

Merged
archlemon merged 3 commits into
mainfrom
fix/audit-config-schemas
Nov 24, 2026
Merged

archlemon merged 3 commits into
mainfrom
fix/audit-config-schemas

Conversation

@archlemon

@archlemon archlemon commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #88
Closes #91

Stacked on #90 (base refactor/b15), so the products can move to one pdbcore commit that contains all three PRs. It retargets as the lower PRs merge.

Schema order (#88)

  • introspect.Introspect copies its schemas argument instead of storing and then sorting the caller's slice.
  • Catalog.Schemas keeps the configured order. The products treat that order as a priority order, and it is the order ParseTypeName already searched in.
  • Hash sorts its own copy, so hashes, and with them schema caches and the drift check, do not change.
  • Before this fix, a live boot alphabetised schema.schemas and a schema-cache boot did not. In pdbr, the bare aliases (/users, /rpc/{fn}) went to the alphabetically first schema after a live boot; they now follow schema.schemas[0] however the server starts. The pdbr PR notes this in its changelog.
  • Tests:
    • DB-backed: Introspect leaves the caller's slice unchanged, and Catalog.Schemas neither shares that slice nor reorders it.
    • Unit: the hash ignores schema order.

Doubled underscore after the section (#91)

  • An environment variable such as PDBQ_ROLES__ALLOWED maps to roles_allowed. That has no section of its own, so strict loading used to drop it silently.
  • Load now treats a key that starts with a section name (or a moved or removed key's section) followed by _ as inside that section. It reports the variable with the corrected spelling, for example did you mean PDBQ_ROLES_ALLOWED?, or with the moved-to hint.
  • Variables outside every section (PDBQ_TEST_DATABASE_URL) stay ignored. Tests cover both cases.

Shared durations

  • ValidateDatabase is new. It rejects:
    • a negative database.max_conns (0 stays the pgx pool default)
    • a non-positive database.connect_timeout (0 waited forever)
    • a negative database.statement_timeout (0 still disables it)
  • ValidateIdentity rejects a non-positive auth.jwt.jwks_cache_ttl when auth.jwt.jwks_url is set. Before, it silently became one hour.
  • ValidateWatch and watch.New reject a non-positive poll interval. The polling fallback panicked on one.
  • server.request_timeout lives in the products and is out of scope here.

CI

Like #90, the downstream job fails until the pdbq and pdbr PRs merge.

Tests

  • go test -race ./..., go vet, golangci-lint
  • DB-backed introspect, watch and testutil suites on PostGIS 18
  • act lint-test

@archlemon
archlemon changed the base branch from refactor/b15 to main November 24, 2026 01:54
Introspect stored the caller's schemas slice in the catalog and then
sorted it in place, so a product's schema.schemas configuration was
alphabetised by a live boot (and by every watch rebuild) but not by a
schema-cache boot. Introspect now copies the slice and Catalog.Schemas
keeps the configured order, which products treat as a priority order;
Hash sorts its own copy, so hashes do not change.
An environment variable that doubles the underscore right after its
section (PDBQ_ROLES__ALLOWED maps to roles_allowed) has no section of its
own, so strict loading ignored it and the setting silently kept its
default. Load now treats a key starting with a section name and an
underscore as inside that section and suggests the corrected variable.

ValidateDatabase rejects max_conns below 1, a non-positive
connect_timeout and a negative statement_timeout; ValidateIdentity
rejects a non-positive JWKS cache TTL when a JWKS URL is set (it fell
back to one hour); ValidateWatch and watch.New reject a non-positive poll
interval, on which the polling fallback panicked.
pdbq documents and tests database.max_conns: 0 as the pgx pool default;
only a negative value is invalid.
@archlemon
archlemon force-pushed the fix/audit-config-schemas branch from e611026 to 5d6cc67 Compare November 24, 2026 01:54
@archlemon
archlemon merged commit b353332 into main Nov 24, 2026
3 of 5 checks passed
@archlemon
archlemon deleted the fix/audit-config-schemas branch November 24, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant