+ This looks like a schema-changing (DDL) statement. Schema changes are best tracked as
+ migrations rather than run ad-hoc. Create a migration for it instead?
+
+
{promptStatement ?? ''}
+
+
+
+
+
+
+
+
diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte
index 476869900d..d0cd91e2fd 100644
--- a/frontend/src/lib/components/Editor.svelte
+++ b/frontend/src/lib/components/Editor.svelte
@@ -43,6 +43,7 @@
import { editorFontSize } from '$lib/editorFontSize.svelte'
import { createHash as randomHash } from '$lib/editorLangUtils'
import { workspaceStore } from '$lib/stores'
+ import DdlMigrationGuard from './DdlMigrationGuard.svelte'
import {
type Preview,
ResourceService,
@@ -213,6 +214,26 @@
let lang = $state(scriptLangToEditorLang(untrack(() => scriptLang)))
+ // On a postgres script targeting a datatable, DDL statements are intercepted
+ // on run (cmd+enter) and offered as migrations instead.
+ let datatableForMigrations = $derived(
+ scriptLang === 'postgresql' &&
+ typeof args?.database === 'string' &&
+ args.database.startsWith('datatable://')
+ ? args.database.slice('datatable://'.length).split('/')[0]
+ : undefined
+ )
+ let ddlGuard = $state(undefined)
+
+ async function runCmdEnterWithDdlGuard() {
+ if (datatableForMigrations && ddlGuard) {
+ const res = await ddlGuard.guard(getCode())
+ if (!res.proceed) return
+ if (res.code !== getCode()) setCode(res.code)
+ }
+ cmdEnterAction?.()
+ }
+
let filePath = $state(computePath(untrack(() => path)))
let initialPath: string | undefined = $state(untrack(() => path))
@@ -1539,7 +1560,8 @@
editor?.addCommand(KeyMod.CtrlCmd | KeyCode.Enter, function () {
updateCode()
- shouldBindKey && cmdEnterAction && cmdEnterAction()
+ if (!shouldBindKey || !cmdEnterAction) return
+ void runCmdEnterWithDdlGuard()
})
editor?.addCommand(KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Digit7, function () {
@@ -2067,6 +2089,13 @@
+{#if datatableForMigrations && $workspaceStore}
+
+{/if}
{#if !editor}