fix(sql-editor): stop splitting routine bodies on bare END - #251
Merged
Conversation
Routine DDL nesting treated every END as a block closer, so aliases like AS end or SELECT end closed BEGIN early and turned later DELETE/UPDATE lines into top-level cells. Track BEGIN/CASE/TRY/CATCH on a stack and only close BEGIN at statement-leading END. Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
objectsAtVersion loads by hash order, so a table-owned trigger can appear before table:OWNER in the same owner group. Both are container types; hydrate used find(isLokeeContainerType) and could emit ALTER TABLE for the trigger name during revert. Pick the same ordered type:OWNER key as the blueprint assembler. Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
Contributor
Author
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_104530e7-9c23-4666-9deb-ddd6a34e6fa9) |
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
Audit of recent SQL editor commits (#245 safe-mode SELECT joins, #246 routine DDL one-cell, #247 grid copy) found one high-confidence critical correctness bug in #246.
Routine DDL nesting treated every unqualified
ENDas a block closer. Bodies that usedendas an alias/column/variable (AS end,SELECT end,DECLARE end INT) closedBEGINearly, so laterDELETE/UPDATElines became separate top-level cells and could run against the live DB on Run All.Fix
BEGIN/CASE/BEGIN TRY/BEGIN CATCHon a stackBEGINonly for statement-leadingEND(not mid-expression identifiers)TRY/CATCHframes onEND TRY/END CATCHso following statements are not swallowedTest plan
npx vitest run packages/sql/src/modules/sql-splitter.test.ts(96 passed)AS end/DECLARE end/END ASCASE expr /BEGIN TRY…CATCHAudit notes (no other criticals)
isWriteStatementconfirm path unchanged — no write bypass foundNote
High Risk
Routine splitter bugs could split destructive DML out of procedure bodies and execute it as top-level SQL on Run All; hydrate mis-picks could emit wrong DDL on weave revert paths.
Overview
Fixes critical SQL editor splitting where routine DDL nesting treated every unqualified
ENDas closingBEGIN. Aliases and columns namedend(AS end,SELECT end,DECLARE end INT) could end the routine cell early so laterDELETE/UPDATEbecame separate top-level cells and could run on Run All.The splitter now tracks
BEGIN/CASE/BEGIN TRY/BEGIN CATCHon a stack and only closesBEGINon statement-leadingEND, not mid-expression identifiers. SQL ServerEND TRY/END CATCHclose the matching frames. New tests cover those cases plusBEGIN TRY…CATCHbatches.Separately,
pickOwnerContainerpicks the owner-level container from a same-owner object group using the same orderedtype:OWNERkeys as blueprint assembly.hydrateTableSchemasuses it instead of the first container-typed object, so a table-owned trigger that appears beforetable:CUSTOMERis not mistaken for the table (wrong DDL likeALTER TABLE trg_auditvscustomer).pickOwnerContainerandisLokeeContainerTypeare re-exported from the package entry.Reviewed by Cursor Bugbot for commit 671477e. Bugbot is set up for automated code reviews on this repo. Configure here.