refactor(ast): add named DropBehavior constants#4461
Draft
luongs3 wants to merge 1 commit into
Draft
Conversation
The pg_query DropBehavior enum currently lives as a bare `type DropBehavior uint` — callers that compare against the wire values have to write magic numbers (`stmt.Behavior == 2` for CASCADE). Add named constants matching pganalyze/pg_query_go's DropBehavior enum so usage sites can read `stmt.Behavior == ast.DropBehaviorCascade` instead, and survive a future pg_query enum reshuffle without silently miscompiling. No behavior change — just constants. Existing code that compares to integer literals continues to work; this is purely additive. Follow-up to the review on sqlc-dev#4419 (which currently uses `Behavior == 2` literal): happy to apply the same rename in that PR's diff once it lands, or in a separate sweep PR depending on what the maintainers prefer. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Adds named
DropBehaviorconstants tointernal/sql/ast/drop_behavior.go. No behavior change — purely additive.Why
internal/sql/astcurrently has:The numeric values come from pganalyze/pg_query_go's
DropBehaviorenum, but they are nowhere named on the sqlc side. Callers comparing against the wire value have to writestmt.Behavior == 2for CASCADE — a magic number that's invisible to grep and silently miscompiles if pg_query reshuffles the enum.This PR adds:
Comments at the top of the file document where the values come from so future contributors don't have to chase the pg_query source.
What does NOT change
Context
This is the follow-up I offered in a review note on #4419. That PR uses
stmt.Behavior == 2ininternal/sql/catalog/table.go. Once the constants land, refactoring those use-sites tostmt.Behavior == ast.DropBehaviorCascadeis a 1-line change — happy to bundle into #4419 (if maintainers prefer one PR) or send as a separate sweep PR after #4419 merges. Both work; I have no preference.