Conversation
…functions (#283) When using temporary schemas for plan generation, column defaults referencing functions in the target schema (e.g., public.uuid_generate_v1mc()) were not properly normalized, causing pgschema to detect changes where none existed. The root cause: normalizeIR ran with temp schema names (pgschema_tmp_*), so same-schema qualifier stripping couldn't match the target schema prefix. After normalizeSchemaNames renamed temp→target, re-running normalization with the correct schema context fixes the mismatch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where pgschema plan would generate spurious ALTER TABLE statements for column defaults that reference functions in the target schema. The issue occurred because IR normalization ran with temporary schema names before they were replaced with target schema names, preventing same-schema qualifier stripping from working correctly.
Changes:
- Exported
NormalizeIRfunction to allow re-running normalization after schema name replacement - Added call to re-run
ir.NormalizeIR()afternormalizeSchemaNames()in plan generation - Added comprehensive test coverage including unit tests and integration test
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ir/normalize.go | Exported NormalizeIR function with documentation explaining idempotency and the need to re-run after schema renaming |
| ir/normalize_test.go | Added unit tests validating normalization behavior with temp schemas and the re-run mechanism |
| cmd/plan/plan.go | Added call to re-run ir.NormalizeIR() after schema name replacement with detailed explanatory comments |
| testdata/diff/create_table/issue_283_function_default_schema_qualifier/* | Added integration test data validating the full plan workflow shows no spurious changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…re-running normalizeIR (#283) Move the fix for issue #283 into normalizeSchemaNames itself: after replacing temp schema names with the target schema, strip redundant same-schema function and type cast qualifiers from expression fields (column defaults, generated expressions, check clauses, policy expressions, trigger conditions). This is more targeted than re-running the full normalizeIR pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ifier stripping The table_fk_to_generated_column test fixture had "public.calc_priority()" in its expected plan output. With the same-schema qualifier stripping fix, the correct output is now "calc_priority()" without the redundant qualifier. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Integration tests (issue_283_function_default_schema_qualifier and dependency_table_fk_to_generated_column) already cover the end-to-end behavior. The unit tests for normalizeDefaultValue and normalizeSchemaNames were testing pre-existing or already-covered behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
ALTER TABLE ... ALTER COLUMN ... SET DEFAULTchanges when usingpgschema planwith column defaults that reference functions in the target schema (e.g.,uuid_generate_v1mc())normalizeIRfirst ran with temporary schema names (pgschema_tmp_*), so same-schema qualifier stripping couldn't match thepublic.prefix. AfternormalizeSchemaNamesrenamed temp→target, the qualifiers were already baked innewSameSchemaQualifierStripperinnormalizeSchemaNamesthat strips redundant same-schema function/type qualifiers from expression fields (column defaults, generated expressions, check clauses, policy expressions, trigger conditions) after replacing temp schema names with the target schemaFixes #283
Test plan
issue_283_function_default_schema_qualifiervalidates the full plan workflow with function defaults produces no spurious changesdependency_table_fk_to_generated_columntest updated — generated column expressions now correctly omit redundantpublic.qualifier🤖 Generated with Claude Code