From a57fef1d2472564362a57dff64137c49c2086010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ph=C3=BAc=20L=C6=B0=C6=A1ng?= Date: Thu, 28 May 2026 09:52:40 +0000 Subject: [PATCH] refactor(ast): add named DropBehavior constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #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) --- internal/sql/ast/drop_behavior.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/sql/ast/drop_behavior.go b/internal/sql/ast/drop_behavior.go index 557073cd86..98ad07f235 100644 --- a/internal/sql/ast/drop_behavior.go +++ b/internal/sql/ast/drop_behavior.go @@ -1,7 +1,20 @@ package ast +// DropBehavior captures whether a Postgres DROP statement was qualified with +// RESTRICT or CASCADE. The numeric values mirror pganalyze/pg_query_go's +// DropBehavior enum: +// +// DropBehavior_UNDEFINED = 0 (no behavior word supplied — same as RESTRICT in PG) +// DROP_RESTRICT = 1 +// DROP_CASCADE = 2 type DropBehavior uint +const ( + DropBehaviorUndefined DropBehavior = 0 + DropBehaviorRestrict DropBehavior = 1 + DropBehaviorCascade DropBehavior = 2 +) + func (n *DropBehavior) Pos() int { return 0 }