Fix ALTER EXTENSION deparsing issues #229
Closed
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.
Fix ALTER EXTENSION deparsing and add DRY refactoring for ObjectType
Summary
This PR fixes multiple issues with
ALTER EXTENSIONstatement deparsing and introduces a DRY refactoring for ObjectType keyword mapping:Fixed
ALTER EXTENSION UPDATE TOdeparsing: The deparser was checking fordefname === 'to'but the AST usesdefname === 'new_version', causing it to outputNEW_VERSION 2.0instead ofUPDATE TO '2.0'. Also added proper string quoting since DefElem context returns unquoted values.Fixed
ALTER EXTENSION SET SCHEMAdeparsing: Changed output fromSCHEMAtoSET SCHEMAto match PostgreSQL syntax.Implemented
AlterExtensionContentsStmthandler: Added support forALTER EXTENSION ... ADD/DROP FUNCTION/...statements which were previously unsupported.DRY refactoring: Created centralized
getObjectTypeKeyword()method to eliminate duplicate switch statements inAlterOwnerStmtandAlterObjectSchemaStmt. This reduces ~200 lines of duplicated code.Test results: All 285 test suites pass (655 tests total), including the new
misc-missing-types.test.tsthat was previously failing.Review & Testing Checklist for Human
ALTER EXTENSION UPDATE TO '2.0'produces correctly quoted output - The string quoting logic in DefElem is manually added because DefElem context returns unquoted strings. Test that version strings are properly quoted in the output.getObjectTypeKeyword()is now used by multiple statement types. While CI passes, manually verify a fewALTER ... OWNER TOstatements with different object types still work correctly.ALTER EXTENSION ADD/DROPwith different object types - The newAlterExtensionContentsStmthandler assumes action values of 1 (ADD) and -1 (DROP). Verify this works for both ADD and DROP operations with various object types (FUNCTION, TYPE, etc.).Notes
AlterExtensionContentsStmtare hardcoded based on the AST structure. If these values are incorrect, the handler will produce wrong output.getObjectTypeKeyword()method includes a comprehensive mapping of all ObjectType enum values, but some may not be tested by the current fixture set.Link to Devin run: https://app.devin.ai/sessions/505114984e764debaca3c75b2dab458c
Requested by: Dan Lynch ([email protected]) / @pyramation