-
Notifications
You must be signed in to change notification settings - Fork 29
Optimize default value handling during type changes #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] WIP address feedback on USING clause for text-to-enum conversions
Optimize default value handling during type changes
Dec 18, 2025
tianzhou
approved these changes
Dec 18, 2025
Contributor
tianzhou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tianzhou
added a commit
that referenced
this pull request
Dec 18, 2025
* fix: add USING clause for text-to-enum type conversions (#190) When converting columns from text-like types (text, varchar, char) to custom types like ENUMs, PostgreSQL requires an explicit USING clause. Additionally, columns with default values need special handling during type changes: drop default, alter type, then re-add default. Changes: - Add USING clause when converting from text-like to non-built-in types - Handle default values during type change (drop -> alter -> set) - Add IsBuiltInType and IsTextLikeType helpers to ir/normalize.go - Add test cases for text-to-enum conversion with and without defaults 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update internal/diff/column.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Optimize default value handling during type changes (#210) * Initial plan * Optimize default value handling for type changes without USING clause Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * Fix array type handling in IsTextLikeType for USING clause generation (#211) * Initial plan * fix: handle array types in IsTextLikeType function Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * refactor: consolidate array type tests into existing alter_column_types test Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * chore: add missing updated plan --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
alecthomas
pushed a commit
to alecthomas/pgschema
that referenced
this pull request
Jan 26, 2026
* fix: add USING clause for text-to-enum type conversions (pgplex#190) When converting columns from text-like types (text, varchar, char) to custom types like ENUMs, PostgreSQL requires an explicit USING clause. Additionally, columns with default values need special handling during type changes: drop default, alter type, then re-add default. Changes: - Add USING clause when converting from text-like to non-built-in types - Handle default values during type change (drop -> alter -> set) - Add IsBuiltInType and IsTextLikeType helpers to ir/normalize.go - Add test cases for text-to-enum conversion with and without defaults 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update internal/diff/column.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Optimize default value handling during type changes (pgplex#210) * Initial plan * Optimize default value handling for type changes without USING clause Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * Fix array type handling in IsTextLikeType for USING clause generation (pgplex#211) * Initial plan * fix: handle array types in IsTextLikeType function Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * refactor: consolidate array type tests into existing alter_column_types test Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com> * chore: add missing updated plan --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.
The default value handling logic unnecessarily dropped and re-added defaults for all type changes, even when PostgreSQL could implicitly convert types (e.g.,
integer → bigint).Changes
internal/diff/column.goto evaluateneedsUsingClause()once and use it to determine when defaults must be dropped/re-addedtext → enum)integer → bigint) now preserve defaults automaticallyExample
For a column changing from
integer DEFAULT 1tobigint DEFAULT 1:Before:
After:
For
text DEFAULT 'pending'toaction_type DEFAULT 'pending', the DROP/SET DEFAULT sequence is still correctly generated since USING is required.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.