Skip to content

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

chore(sql-editor): enable DML/DDL by default if databaseChangeMode is EDITOR (#13791)

Liu Jif11ee6304b71
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index d80e26dcc5..0edfef2b61 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -57,6 +57,10 @@ const useExecuteSQL = () => {
const tabStore = useSQLEditorTabStore();
const sqlEditorStore = useSQLEditorStore();
const sqlCheckStyle = useAppFeature("bb.feature.sql-editor.sql-check-style");
+ const changeMode =
+ useAppFeature("bb.feature.database-change-mode").value === "EDITOR"
+ ? "RW"
+ : "RO";
const notify = (
type: BBNotificationStyle,
title: string,
@@ -305,7 +309,7 @@ const useExecuteSQL = () => {
try {
let resultSet: SQLResultSetV1;
- if (mode === "READONLY") {
+ if (changeMode === "RO") {
const instance = isValidDatabaseName(database.name)
? database.instance
: params.connection.instance;
diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.ts
index 9cb868f0db..0077862577 100644
--- a/frontend/src/store/modules/sqlEditor/tab.ts
+++ b/frontend/src/store/modules/sqlEditor/tab.ts
@@ -78,7 +78,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
...stored,
id,
});
- if (tab.mode === "ADMIN") {
+ if (tab.mode !== DEFAULT_SQL_EDITOR_TAB_MODE) {
// Do not enter ADMIN mode initially
tab.mode = DEFAULT_SQL_EDITOR_TAB_MODE;
}
diff --git a/frontend/src/types/sqlEditor/tab.ts b/frontend/src/types/sqlEditor/tab.ts
index afa4370de5..767d0566c7 100644
--- a/frontend/src/types/sqlEditor/tab.ts
+++ b/frontend/src/types/sqlEditor/tab.ts
@@ -12,9 +12,8 @@ export type SQLEditorTabStatus =
| "DIRTY" // edited
| "CLEAN"; // saved to a remote sheet
-// STANDARD not supported by backend so far
-export type SQLEditorTabMode = "STANDARD" | "READONLY" | "ADMIN";
-export const DEFAULT_SQL_EDITOR_TAB_MODE: SQLEditorTabMode = "READONLY";
+export type SQLEditorTabMode = "WORKSHEET" | "ADMIN";
+export const DEFAULT_SQL_EDITOR_TAB_MODE: SQLEditorTabMode = "WORKSHEET";
export type BatchQueryContext = {
// databases is used to store the selected database names.
diff --git a/frontend/src/views/sql-editor/EditorCommon/AdminModeButton.vue b/frontend/src/views/sql-editor/EditorCommon/AdminModeButton.vue
index 18d74753c1..66078ddd9c 100644
--- a/frontend/src/views/sql-editor/EditorCommon/AdminModeButton.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/AdminModeButton.vue
@@ -48,7 +48,7 @@ const { currentTab, isDisconnected } = storeToRefs(tabStore);
const showButton = computed(() => {
if (!allowAdmin.value) return false;
const mode = currentTab.value?.mode;
- return mode === "READONLY" || mode === "STANDARD";
+ return mode === "WORKSHEET";
});
const enterAdminMode = async () => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index af07439da6..51cecb3935 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -209,7 +209,7 @@ const { instance } = useConnectionOfCurrentSQLEditorTab();
const showSheetsFeature = computed(() => {
const mode = currentTab.value?.mode;
- return mode === "READONLY" || mode === "STANDARD";
+ return mode === "WORKSHEET";
});
const allowQuery = computed(() => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
index b63960d43a..eaa08d9277 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
@@ -32,7 +32,7 @@
<div class="execute-hint-content mt-4 flex justify-between">
<div
- v-if="actions.action && actions.admin"
+ v-if="actions.issue && actions.admin"
class="flex justify-start items-center space-x-2"
>
<AdminModeButton @enter="$emit('close')" />
@@ -40,16 +40,11 @@
<div class="flex flex-1 justify-end items-center space-x-2">
<NButton @click="handleClose">{{ $t("common.close") }}</NButton>
<NButton
- v-if="actions.action"
+ v-if="actions.issue"
type="primary"
- @click="handleClickActionButton"
+ @click="handleClickCreateIssue"
>
- <template v-if="actions.action === 'CREATE_ISSUE'">
- {{ descriptions.action }}
- </template>
- <template v-if="actions.action === 'STANDARD_MODE'">
- {{ $t("sql-editor.standard-mode.self") }}
- </template>
+ {{ descriptions.action }}
</NButton>
<AdminModeButton v-else @enter="$emit('close')" />
</div>
@@ -73,7 +68,6 @@ import {
useSQLEditorTabStore,
} from "@/store";
import { extractProjectResourceName, hasWorkspacePermissionV2 } from "@/utils";
-import { useSQLEditorContext } from "../context";
import AdminModeButton from "./AdminModeButton.vue";
const emit = defineEmits<{
@@ -86,7 +80,6 @@ const DMLIssueTemplate = "bb.issue.database.data.update";
const router = useRouter();
const { t } = useI18n();
const tabStore = useSQLEditorTabStore();
-const { standardModeEnabled } = useSQLEditorContext();
const disallowNavigateToConsole = useAppFeature(
"bb.feature.disallow-navigate-to-console"
);
@@ -104,19 +97,17 @@ const isDDL = computedAsync(async () => {
const actions = computed(() => {
type Actions = {
admin: boolean;
- action: "STANDARD_MODE" | "CREATE_ISSUE" | undefined;
+ issue: boolean;
};
const actions: Actions = {
admin: false,
- action: undefined,
+ issue: false,
};
if (hasWorkspacePermissionV2("bb.instances.adminExecute")) {
actions.admin = true;
}
- if (standardModeEnabled.value) {
- actions.action = "STANDARD_MODE";
- } else if (!disallowNavigateToConsole.value) {
- actions.action = "CREATE_ISSUE";
+ if (!disallowNavigateToConsole.value) {
+ actions.issue = true;
}
return actions;
@@ -130,15 +121,12 @@ const descriptions = computed(() => {
action: "",
reaction: "",
};
- const { admin, action } = actions.value;
- if (action === "CREATE_ISSUE") {
+ const { admin, issue } = actions.value;
+ if (issue) {
descriptions.action = isDDL.value
? t("database.edit-schema")
: t("database.change-data");
descriptions.reaction = t("sql-editor.and-submit-an-issue");
- } else if (action === "STANDARD_MODE") {
- descriptions.action = t("sql-editor.standard-mode.self");
- descriptions.reaction = t("sql-editor.to-enable-standard-mode");
} else if (admin) {
descriptions.action = t("sql-editor.admin-mode.self");
descriptions.reaction = t("sql-editor.to-enable-admin-mode");
@@ -184,27 +172,7 @@ const gotoCreateIssue = () => {
window.open(route.fullPath, "_blank");
};
-const changeToStandardMode = () => {
- const tab = tabStore.currentTab;
- if (!tab) {
- return;
- }
- if (tab.mode === "ADMIN") {
- return;
- }
- tab.mode = "STANDARD";
- emit("close");
-};
-
-const handleClickActionButton = () => {
- const { action } = actions.value;
- if (action === "CREATE_ISSUE") {
- gotoCreateIssue();
- return;
- }
- if (action === "STANDARD_MODE") {
- changeToStandardMode();
- return;
- }
+const handleClickCreateIssue = () => {
+ gotoCreateIssue();
};
</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton.vue b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton.vue
index 689631403c..6dcbb32a65 100644
--- a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton.vue
@@ -60,7 +60,7 @@ const showButton = computed(() => {
return (
openAIKey.value &&
!tabStore.isDisconnected &&
- tabStore.currentTab?.mode !== "ADMIN"
+ tabStore.currentTab?.mode === "WORKSHEET"
);
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue
index a31c785e3b..d5c2a5ef6e 100644
--- a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue
@@ -71,17 +71,6 @@
</template>
</ResultLimitSelect>
</div>
- <div
- v-if="showQueryModeSelect"
- class="border-t pt-1 -mx-2"
- style="width: calc(100% + 1rem)"
- >
- <QueryModeSelect
- :disabled="isExecutingSQL"
- placement="right-start"
- trigger="hover"
- />
- </div>
</div>
</template>
</NPopover>
@@ -106,8 +95,6 @@ import {
} from "@/types/proto/v1/org_policy_service";
import { readableDataSourceType } from "@/utils";
import { getAdminDataSourceRestrictionOfDatabase } from "@/utils";
-import { useSQLEditorContext } from "../context";
-import QueryModeSelect from "./QueryModeSelect.vue";
import ResultLimitSelect from "./ResultLimitSelect.vue";
defineProps<{
@@ -116,7 +103,6 @@ defineProps<{
const { t } = useI18n();
const tabStore = useSQLEditorTabStore();
-const { standardModeEnabled } = useSQLEditorContext();
const { connection, database } = useConnectionOfCurrentSQLEditorTab();
const policyStore = usePolicyV1Store();
@@ -124,10 +110,6 @@ const show = computed(() => {
return tabStore.currentTab?.mode !== "ADMIN";
});
-const isExecutingSQL = computed(
- () => tabStore.currentTab?.queryContext?.status === "EXECUTING"
-);
-
const adminDataSourceRestriction = computed(() => {
if (!database.value) {
return {
@@ -147,17 +129,6 @@ const dataSources = computed(() => {
return orderBy(database.value.instanceResource.dataSources, "type");
});
-const showQueryModeSelect = computed(() => {
- const tab = tabStore.currentTab;
- if (!tab) {
- return false;
- }
- if (!standardModeEnabled.value) {
- return false;
- }
- return tab.mode !== "ADMIN";
-});
-
const dataSourceUnaccessibleReason = (
dataSource: DataSource
): string | undefined => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vue b/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vue
deleted file mode 100644
index 76ab82247d..0000000000
--- a/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
- <NPopover placement="bottom" trigger="click">
- <template #trigger>
- <NButton
- quaternary
- style="justify-content: start; --n-padding: 0 8px; width: 100%"
- :disabled="disabled"
- >
- {{ $t(`sql-editor.tab-mode.${tab.mode.toLowerCase()}`) }}
- </NButton>
- </template>
- <div class="flex flex-col gap-2 whitespace-nowrap">
- <p class="font-semibold">{{ $t("common.mode") }}</p>
-
- <NRadioGroup v-model:value="tab.mode" class="!flex flex-col gap-2">
- <NRadio value="READONLY" class="flex flex-row">
- <div class="flex flex-col gap-1 text-sm">
- <p class="font-normal">
- {{ $t("sql-editor.tab-mode.readonly") }}
- </p>
- <p class="text-control-light text-xs">
- {{ $t("sql-editor.tab-mode.description.readonly") }}
- </p>
- </div>
- </NRadio>
- <NRadio value="STANDARD" class="flex flex-row">
- <div class="flex flex-col gap-1 text-sm">
- <p class="font-normal">
- {{ $t("sql-editor.tab-mode.standard") }}
- </p>
- <p class="text-control-light text-xs">
- {{ $t("sql-editor.tab-mode.description.standard") }}
- </p>
- </div>
- </NRadio>
- </NRadioGroup>
- </div>
- </NPopover>
-</template>
-
-<script lang="ts" setup>
-import { NButton, NPopover, NRadio, NRadioGroup } from "naive-ui";
-import { computed } from "vue";
-import { useSQLEditorTabStore } from "@/store";
-
-defineProps<{
- disabled?: boolean;
-}>();
-
-const tabStore = useSQLEditorTabStore();
-
-const tab = computed(() => {
- return tabStore.currentTab!;
-});
-</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue b/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
index 0687ceeb6a..f74c734d29 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
@@ -60,7 +60,7 @@ const hasReadonlyDataSource = computed(() => {
const showReadonlyDatasourceHint = computed(() => {
return (
- tabStore.currentTab?.mode === "READONLY" &&
+ tabStore.currentTab?.mode === "WORKSHEET" &&
isValidInstanceName(props.instance.name) &&
!hasReadonlyDataSource.value
);
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index a512e25756..05aaa69c8a 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -2,13 +2,7 @@
<div class="w-full flex-1 flex flex-row items-stretch overflow-hidden">
<Panels>
<template #code-panel>
- <StandardPanel
- v-if="
- !currentTab ||
- currentTab.mode === 'READONLY' ||
- currentTab.mode === 'STANDARD'
- "
- />
+ <StandardPanel v-if="!currentTab || currentTab.mode === 'WORKSHEET'" />
<TerminalPanel v-else-if="currentTab.mode === 'ADMIN'" />
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
index 99eb2dac35..4604c508a2 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
@@ -1,6 +1,6 @@
<template>
<Splitpanes
- v-if="!tab || tab.mode === 'READONLY' || tab.mode === 'STANDARD'"
+ v-if="!tab || tab.mode === 'WORKSHEET'"
horizontal
class="default-theme"
:dbl-click-splitter="false"
@@ -59,7 +59,7 @@
<script lang="ts" setup>
import { storeToRefs } from "pinia";
import { Pane, Splitpanes } from "splitpanes";
-import { computed, defineAsyncComponent, watch } from "vue";
+import { computed, defineAsyncComponent } from "vue";
import { BBSpin } from "@/bbkit";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import { AIChatToSQL } from "@/plugins/ai";
@@ -84,7 +84,7 @@ const SQLEditor = defineAsyncComponent(() => import("./SQLEditor.vue"));
const tabStore = useSQLEditorTabStore();
const { currentTab: tab, isDisconnected } = storeToRefs(tabStore);
-const { showAIChatBox, standardModeEnabled } = useSQLEditorContext();
+const { showAIChatBox } = useSQLEditorContext();
const { instance } = useConnectionOfCurrentSQLEditorTab();
const allowReadonlyMode = computed(() => {
@@ -122,19 +122,4 @@ const handleApplyStatement = async (
});
}
};
-
-watch(
- [() => tab.value?.id, standardModeEnabled],
- () => {
- if (!tab.value) return;
- // Fallback to READONLY mode if standard.value mode is not allowed.
- if (!standardModeEnabled.value && tab.value.mode === "STANDARD") {
- tab.value.mode = "READONLY";
- }
- },
- {
- immediate: true,
- deep: false,
- }
-);
</script>
diff --git a/frontend/src/views/sql-editor/TabList/ContextMenu.vue b/frontend/src/views/sql-editor/TabList/ContextMenu.vue
index d58b78a61b..74bd3ce914 100644
--- a/frontend/src/views/sql-editor/TabList/ContextMenu.vue
+++ b/frontend/src/views/sql-editor/TabList/ContextMenu.vue
@@ -60,7 +60,7 @@ const options = computed((): DropdownOption[] => {
];
const { tab } = state.value;
- if (tab.mode === "READONLY" || tab.mode === "STANDARD") {
+ if (tab.mode === "WORKSHEET") {
const DIVIDER: DropdownOption = {
type: "divider",
key: "DIVIDER",
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
index 8170a3ca8f..04ce17c510 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
@@ -56,10 +56,7 @@ const icon = computed((): IconType | undefined => {
return "close";
}
const { mode, status } = props.tab;
- if (
- (mode === "READONLY" || mode === "STANDARD") &&
- (status === "DIRTY" || status === "NEW")
- ) {
+ if (mode === "WORKSHEET" && (status === "DIRTY" || status === "NEW")) {
return "unsaved";
}
return "close";
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
index 04fb80591b..069cc7362c 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
@@ -18,11 +18,7 @@
>
<div class="body">
<Prefix :tab="tab" :index="index" />
- <Label
- v-if="tab.mode === 'READONLY' || tab.mode === 'STANDARD'"
- :tab="tab"
- :index="index"
- />
+ <Label v-if="tab.mode === 'WORKSHEET'" :tab="tab" :index="index" />
<AdminLabel v-else :tab="tab" :index="index" />
<Suffix :tab="tab" :index="index" @close="$emit('close', tab, index)" />
</div>
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index 978dcdb37e..a6d4d07276 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -170,10 +170,7 @@ const handleRemoveTab = async (
focusWhenConfirm = false
) => {
const _defer = defer<boolean>();
- if (
- (tab.mode === "READONLY" || tab.mode === "STANDARD") &&
- tab.status === "DIRTY"
- ) {
+ if (tab.mode === "WORKSHEET" && tab.status === "DIRTY") {
if (focusWhenConfirm) {
tabStore.setCurrentTabId(tab.id);
}
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
index 3febcb648a..b7bc746fd8 100644
--- a/frontend/src/views/sql-editor/context.ts
+++ b/frontend/src/views/sql-editor/context.ts
@@ -1,9 +1,8 @@
import Emittery from "emittery";
import type { InjectionKey, Ref } from "vue";
-import { computed, inject, provide, ref } from "vue";
-import { useSQLEditorStore, useSettingV1Store } from "@/store";
+import { inject, provide, ref } from "vue";
+import { useSQLEditorStore } from "@/store";
import type { ComposedDatabase, SQLEditorTab } from "@/types";
-import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";
import type { Worksheet } from "@/types/proto/v1/worksheet_service";
export type AsidePanelTab = "SCHEMA" | "WORKSHEET" | "HISTORY";
@@ -43,7 +42,6 @@ export type SQLEditorContext = {
}
| undefined
>;
- standardModeEnabled: Ref<boolean>;
events: SQLEditorEvents;
@@ -66,12 +64,6 @@ export const provideSQLEditorContext = () => {
showAIChatBox: ref(false),
schemaViewer: ref(undefined),
events: new Emittery(),
- standardModeEnabled: computed(() => {
- return (
- useSettingV1Store().workspaceProfileSetting?.databaseChangeMode ===
- DatabaseChangeMode.EDITOR
- );
- }),
maybeSwitchProject: (project) => {
if (editorStore.project !== project) {