Conversation
pg_get_viewdef() can produce different schema qualification for extension functions depending on search_path differences between embedded postgres (desired state) and target database (current state). For example, ltree's nlevel() might appear as "public.nlevel()" on one side and "nlevel()" on the other, causing an infinite plan/apply loop. Apply the existing stripSchemaPrefixFromBody() to view definitions during normalization, matching what already happens for function and procedure bodies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes non-converging diffs for views where pg_get_viewdef() renders same-schema references inconsistently (e.g., nlevel() vs public.nlevel()), by normalizing view definitions to strip same-schema qualifiers similarly to existing function/procedure normalization.
Changes:
- Apply
stripSchemaPrefixFromBody()normalization toView.Definitionduring IR normalization. - Update
normalizeViewdocumentation to reflect real-worldpg_get_viewdef()qualification differences (Issue #314). - Add unit test coverage validating stripping behavior across several view-definition cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
ir/normalize.go |
Normalizes view definitions by stripping same-schema qualifiers to prevent repeated view diffs. |
ir/normalize_test.go |
Adds unit tests ensuring view definition normalization strips only same-schema qualifiers and preserves cross-schema/literals. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryApplies existing schema prefix normalization logic to view definitions to fix false positives in schema comparison. Previously, The fix reuses the battle-tested
Key changes:
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: de06964 |
Summary
pgschema planwas reporting the same view change on every run when extension functions (e.g., ltree'snlevel()) appeared with different schema qualification between desired and current state (nlevel()vspublic.nlevel())stripSchemaPrefixFromBody()normalization to view definitions, matching what already happens for function and procedure bodiesFixes #314
Test plan
TestNormalizeViewStripsSchemaPrefixFromDefinitionadded with 6 cases covering: same-schema function stripping, cross-schema preservation, table references, no-op, multiple occurrences, string literal safetyPGSCHEMA_TEST_FILTER="create_view/" go test -v ./internal/diff -run TestDiffFromFilesPGSCHEMA_TEST_FILTER="create_view/" go test -v ./cmd -run TestPlanAndApplygo test -v ./ir🤖 Generated with Claude Code