mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 16:02:14 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user