fix: skip COMMENT cleanup for dropped indexes in psqldef#1064
Merged
gfx merged 1 commit intosqldef:masterfrom Dec 27, 2025
Merged
fix: skip COMMENT cleanup for dropped indexes in psqldef#1064gfx merged 1 commit intosqldef:masterfrom
gfx merged 1 commit intosqldef:masterfrom
Conversation
When an index with a comment is dropped, psqldef was generating COMMENT ON INDEX ... IS NULL after DROP INDEX, causing an error because the index no longer exists. PostgreSQL automatically removes index comments when the index is dropped. This follows the same pattern as dropped columns (ee7a539).
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
Contributor
|
Thank you! |
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
This PR fixes an issue where psqldef generates
COMMENT ON INDEX ... IS NULLstatements for indexes that have already been dropped, causing errors like:Problem
When dropping indexes that have comments, psqldef would:
DROP INDEXstatementsCOMMENT ON INDEX ... IS NULLstatements for the same indexesSince PostgreSQL automatically removes index comments when an index is dropped, the second step fails because the index no longer exists.
Solution
This fix follows the same pattern used for dropped columns (#1055) and dropped tables:
droppedIndexesmap during DDL generationCOMMENT ... IS NULLstatements for indexes that are being droppedChanges
schema/generator.go: AddeddroppedIndexesmap and three helper functions (trackDroppedIndex,droppedIndexKey,isCommentOnDroppedIndex)cmd/psqldef/tests_comments.yml: Added two test cases to verify the fixTest Plan
make buildpassesmake format- no changesmake lint- no errorsmake vulncheck- no vulnerabilitiesmake modernize- no changesgo test ./cmd/psqldef -run="TestApply/DropIndexWithComment"passesThank you for maintaining this excellent tool!