feat: Support incompatible type conversions via DROP/ADD approach #231
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
Resolves #179 by implementing intelligent type coercion analysis that automatically switches to
DROP COLUMN + ADD COLUMN
for incompatible type conversions instead of failing with cast errors.Description
This PR introduces a comprehensive type coercion analysis system that intelligently handles column type changes by categorizing conversions and choosing the appropriate alteration strategy:
smallint
→integer
): UseALTER COLUMN
with minimal lockingtext
→integer
): UseALTER COLUMN
with table rewrite warningsinteger
→timestamptz
): UseDROP COLUMN + ADD COLUMN
with data loss warningsKey Changes
GetTypeCoercionInfo()
function for comprehensive type conversion analysisMotivation
Problem: Previously, attempting to alter incompatible column types (like
integer
totimestamptz
) would fail with cast errors, requiring manual intervention.Solution: This change automatically detects incompatible conversions and uses the appropriate
DROP/ADD
strategy while providing clear warnings about potential data loss.Related Issues:
ACQUIRES_ACCESS_EXCLUSIVE
lock migration hazard if switching between binary-coercible types #52 for improved hazard reporting on binary coercible typesTechnical Details
The implementation categorizes type conversions into three levels:
Testing
New Test Coverage
Regression Testing
Before/After
Before:
After: