plan/apply still fails on extension-owned types even when plan and target schemas agree (gap remaining after #544 / #518)
#518 reported that extensions (e.g. pgvector) installed in non-default schemas cause problems with --plan-host/--plan-db, in two distinct ways:
- False-positive diffs when the plan and target databases disagree on the extension's schema.
- Apply failures when creating tables with extension-owned column types for the first time.
#544 fixed issue (1) with a fail-fast pre-flight check that errors clearly when the two databases disagree on an extension's schema.
However, issue (2) is still open — even when the plan and target databases agree on the extension's schema, #544's check passes cleanly and the failure still happens.
Repro
Install an extension (e.g. pgvector) in a non-public schema (e.g. domain) on both the plan and target databases, then declare a table with a bare extension-owned type reference (embedding vector(384)), matching how pgschema dump itself emits same-schema references. Running pgschema plan fails:
Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_...: ERROR: type vector does not exist (SQLSTATE 42704)
Root cause
The temporary comparison schema's search_path is only ever set to "<temp>", public, so a bare reference to a type owned by an extension installed in a schema other than public (or the temp schema, which never has it) can't resolve when the desired-state SQL is applied there.
Follow-on effects once the crash is fixed
Two more comparison-key issues surface for functions/procedures whose signature uses an extension-owned type:
- Parameter-type stripping and privilege
object_namestripping both only know about the routine's own schema (or the target schema), not about extension schemas. - A function like
vector_search(query_embedding vector, ...)spuriously diffs as drop+recreate / revoke+regrant on every subsequentplan, because itsroutineSchemaduring introspection of the temp schema is the temp schema name, not the extension's real schema.
Status
I have a small, tested fix for all three issues (3 call sites in internal/postgres/external.go and ir/inspector.go) — opening a PR referencing this issue now.
Verified locally end-to-end: the unfixed binary fails with type vector does not exist on plan; the fixed binary plans/applies cleanly, and a subsequent plan returns No changes detected.. go build ./..., go vet ./..., and go test ./... all pass with no regressions.