fix: run DDL migration guard on the script editor Test button

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Diego Imbert
2026-07-03 18:00:54 +02:00
parent 072f2bf053
commit afe025b886
2 changed files with 24 additions and 4 deletions
+11 -2
View File
@@ -223,12 +223,21 @@
)
let ddlGuard = $state<DdlMigrationGuard | undefined>(undefined)
async function runCmdEnterWithDdlGuard() {
// Run the DDL migration guard against the current code. Returns false when the
// user cancels (the run must be aborted); may rewrite the code (migrated
// statements stripped). Exported so run paths that bypass the Monaco
// Cmd+Enter binding (e.g. the Test button) can guard too.
export async function guardDdlBeforeRun(): Promise<boolean> {
if (datatableForMigrations && ddlGuard) {
const res = await ddlGuard.guard(getCode())
if (!res.proceed) return
if (!res.proceed) return false
if (res.code !== getCode()) setCode(res.code)
}
return true
}
async function runCmdEnterWithDdlGuard() {
if (!(await guardDdlBeforeRun())) return
cmdEnterAction?.()
}
@@ -743,7 +743,17 @@
args = nargs
}
export async function runTest(opts?: { cascade?: boolean }) {
export async function runTest(opts?: { cascade?: boolean; skipDdlGuard?: boolean }) {
// Intercept DDL statements (offer to turn them into data table migrations)
// on every run path, not just the editor's Cmd+Enter. `skipDdlGuard` is set
// by the Cmd+Enter action, which already guarded before calling us.
if (!opts?.skipDdlGuard) {
if ((await editor?.guardDdlBeforeRun()) === false) return
// The guard may have rewritten the code (migrated statements stripped);
// `editorCode` is kept in sync by the editor binding, so mirror the
// on:change handler and pull it into `code` before we run.
if (activeModuleTab === null) code = editorCode
}
// When the caller forces a cascade choice (e.g. the canvas runnable
// menu's "Run + trigger N downstream"), also flip the persistent
// `cascadeDownstream` state so the split button's label/icon reflect
@@ -2626,7 +2636,8 @@
} else {
await inferModuleSchema()
}
runTest()
// The Editor already ran the DDL guard before invoking this action.
runTest({ skipDdlGuard: true })
}}
formatAction={async () => {
if (activeModuleTab === null) {