fix: strip same-schema qualifiers from CHECK constraint expressions (#445)#2
Merged
Merged
Conversation
…gplex#445) When comparing desired vs current state, CHECK constraint expressions containing same-schema function/type references were normalized inconsistently. The desired state (from temp schema) had qualifiers stripped via normalizeSchemaNames, but the current state (from target DB) kept qualifiers from pg_get_constraintdef, causing perpetual spurious diffs. Extended normalizeCheckClause to accept the table's schema and strip same-schema function call qualifiers (e.g., public.validate_foo(val) → validate_foo(val)) and type cast qualifiers (e.g., ::public.my_enum → ::my_enum). This matches the existing pattern used by domain constraints, column defaults, and policy expressions. The fix ensures both desired and current state produce identical unqualified expressions regardless of search_path at inspection time. Co-authored-by: AndyC <andyc-valstro@users.noreply.github.com>
🔍 General Code Quality Feedback🔍 Comprehensive Code ReviewConsolidated Feedback
Overall Assessment: The pull request addresses a critical issue with CHECK constraint normalization in the Critical Issues:
Improvements:
Positive Notes:
Next Steps:
By addressing these issues and suggestions, the code quality and maintainability of the project will be significantly improved, leading to a more robust and reliable system. 🤖 Generated by Wellcode.ai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pgschema planwas reporting unresolvable and perpetual diffs on CHECK constraints that reference functions or custom types defined in the same schema being managed. The plan would constantly want to drop and re-create these constraints, even immediately after a successfulpgschema apply.Root cause: When comparing desired vs current state, CHECK constraint expressions were normalized inconsistently:
normalizeSchemaNamesreplaces temp schema references and strips qualifiers, function calls become unqualified (e.g.,validate_foo(val))pg_get_constraintdef()may render same-schema references as qualified (e.g.,public.validate_foo(val)) depending on the session'ssearch_path, andnormalizeCheckClausedid NOT strip theseFix: Extended
normalizeCheckClauseto accept the table's schema and strip same-schema qualifiers from:public.validate_foo(val)→validate_foo(val)::public.status_enum→::status_enumThis matches the existing normalization pattern already used by:
normalizeDomainConstraint)normalizeDefaultValue)normalizePolicyExpression)Cross-schema qualifiers are preserved (e.g.,
other_schema.validate_foo(val)stays qualified).Fixes pgplex#445
Test plan
Added unit tests to
TestNormalizeCheckClausecovering:Added diff/integration test case
testdata/diff/create_table/issue_445_check_constraint_schema_qualifier/verifying no diff when old=new with function-referencing CHECK constraint.All 150+ existing diff tests, dump tests, and integration tests pass with no regressions.