Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add some robustness and logs (#9750)

Liu Ji84d5282aef82
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index a5e1c3eec0..2b2513c8b4 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -224,6 +224,7 @@ import { cloneDeep } from "lodash-es";
import Long from "long";
import { ExpandIcon } from "lucide-vue-next";
import { NButton, NTooltip, useDialog } from "naive-ui";
+import { v1 as uuidv1 } from "uuid";
import { computed, h, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
@@ -304,9 +305,9 @@ const language = useInstanceV1EditorLanguage(
computed(() => database.value.instanceEntity)
);
const filename = computed(() => {
- return `${selectedTask.value.name}.${extensionNameOfLanguage(
- language.value
- )}`;
+ const name = selectedTask.value.name || uuidv1();
+ const ext = extensionNameOfLanguage(language.value);
+ return `${name}.${ext}`;
});
const dialect = computed((): SQLDialect => {
const db = database.value;
diff --git a/frontend/src/components/MonacoEditor/text-model.ts b/frontend/src/components/MonacoEditor/text-model.ts
index 240e27d355..06d1983834 100644
--- a/frontend/src/components/MonacoEditor/text-model.ts
+++ b/frontend/src/components/MonacoEditor/text-model.ts
@@ -1,4 +1,5 @@
import { Uri, editor } from "monaco-editor";
+import slug from "slug";
import { isRef, markRaw, ref, shallowRef, unref, watch } from "vue";
import { Language, MaybeRef } from "@/types";
import { MonacoEditorReady } from "./editor";
@@ -15,13 +16,15 @@ export const createTextModel = (
content: string,
language: string
) => {
- if (TextModelMapByFilename.has(filename)) {
- return TextModelMapByFilename.get(filename)!;
+ console.debug("[createTextModel]", filename);
+ const normalizedFilename = slug(filename);
+ if (TextModelMapByFilename.has(normalizedFilename)) {
+ return TextModelMapByFilename.get(normalizedFilename)!;
}
- const uri = Uri.parse(`/workspace/${filename}`);
+ const uri = Uri.parse(`/workspace/${normalizedFilename}`);
const model = editor.createModel(content, language, uri);
- TextModelMapByFilename.set(filename, model);
+ TextModelMapByFilename.set(normalizedFilename, model);
return model;
};
diff --git a/frontend/src/components/MonacoEditor/utils.ts b/frontend/src/components/MonacoEditor/utils.ts
index 795b1473a4..cd6b2f6a8c 100644
--- a/frontend/src/components/MonacoEditor/utils.ts
+++ b/frontend/src/components/MonacoEditor/utils.ts
@@ -14,7 +14,8 @@ export const extensionNameOfLanguage = (lang: Language) => {
return "redis";
}
// A simple fallback
- return "txt";
+ console.warn("unexpected language", lang);
+ return "sql";
};
export const useEditorContextKey = <
diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
index cecb95df5c..b0a83420b7 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
@@ -22,6 +22,7 @@
</template>
<script lang="ts" setup>
+import { v1 as uuidv1 } from "uuid";
import { computed, nextTick, ref, watch } from "vue";
import type {
AdviceOption,
@@ -99,9 +100,11 @@ const readonly = computed(() => sheetAndTabStore.isReadOnly);
const currentTabId = computed(() => tabStore.currentTabId);
const isSwitchingTab = ref(false);
-const filename = computed(
- () => `${tabStore.currentTab.id}.${extensionNameOfLanguage(language.value)}`
-);
+const filename = computed(() => {
+ const name = tabStore.currentTab.id || uuidv1();
+ const ext = extensionNameOfLanguage(language.value);
+ return `${name}.${ext}`;
+});
watch(currentTabId, () => {
isSwitchingTab.value = true;