Skip to content

Add opt-in schema-scoped PostgreSQL introspection - #2

Draft
Zetazzz wants to merge 2 commits into
mainfrom
agent/scoped-introspection
Draft

Add opt-in schema-scoped PostgreSQL introspection#2
Zetazzz wants to merge 2 commits into
mainfrom
agent/scoped-introspection

Conversation

@Zetazzz

@Zetazzz Zetazzz commented Aug 19, 2026

Copy link
Copy Markdown

Summary

  • add a parameterized schema-scoped query to pg-introspection;
  • retain the transitive relation, constraint, function-signature, type, range, index, inheritance, and extension dependencies needed by the selected schemas;
  • let the existing PgIntrospectionPlugin opt in per PostgreSQL service;
  • fail closed when the result crosses into an unapproved dependency schema or contains a missing type reference.

When scopedIntrospection is unset or false, the existing full-catalog query and default preset are unchanged. A regression test pins the stock SQL to its pre-refactor SHA-256.

Service configuration

Object.assign(makePgService({ schemas: ["app_public"], ... }), {
  scopedIntrospection: true,
  introspectionAllowedDependencySchemas: ["app_private", "extensions"],
  introspectionScopedCatalogTypes: "dependency-closure",
  introspectionCapabilityExtensions: ["pg_trgm"],
});

Scoped-only options without scopedIntrospection are rejected instead of being silently ignored. This PR does not add a replacement plugin, change the default preset, or alter PostgreSQL JIT/session settings.

Correctness coverage

The real PostgreSQL fixture covers cross-schema enum, domain, composite, range/multirange, function signature, foreign-key and inheritance dependencies; ordinary and pg_trgm GIN/GiST indexes; explicit extension capability metadata; unrelated schema exclusion; stock/scoped GraphQL SDL equality; runtime execution; and an unapproved-schema negative case.

Performance evidence

The same query/closure implementation was measured in constructive#1763 with 10 fresh-process samples per arm and identical JIT-off sessions. On the 65,037-pg_class fixture:

  • schema build p50: 4,682 ms → 398 ms (-91.5%);
  • introspection query p50: 3,116 ms → 111 ms (-96.5%);
  • JSON payload: 163.9 MB → 1.06 MB (-99.4%);
  • parsed classes: 64,220 → 270;
  • stock/scoped schema hashes and runtime queries matched.

The small fixture showed a 1.9% build-time overhead, so this remains explicitly opt-in. The benchmark controlled JIT externally; this PR intentionally does not manage it.

Validation

  • pg-introspection: 41 tests passed; build passed
  • graphile-build-pg: 27 tests passed, including 5 real PostgreSQL scoped cases; build passed
  • affected ESLint and Prettier checks passed
  • changeset status and git diff --check passed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant