Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(sql-editor): implement standard mode for SQL Editor (#12532)
Liu Jie6f1afff40db
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 2f5185fc3a..bf1c5dafe4 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -83,7 +83,7 @@ const useExecuteSQL = () => {tab.queryContext.status = "IDLE";};- const executeReadonly = async (params: SQLEditorQueryParams) => {+ const execute = async (params: SQLEditorQueryParams) => {if (!preflight(params)) {return cleanup();}@@ -92,6 +92,10 @@ const useExecuteSQL = () => {if (!tab) {return;}+ const { mode } = tab;+ if (mode === "ADMIN") {+ return;+ }const queryContext = tab.queryContext!;const batchQueryContext = tab.batchQueryContext;const { data } = await parseSQL(params.statement);@@ -147,9 +151,9 @@ const useExecuteSQL = () => {};const { abortController } = queryContext;+ const sqlStore = useSQLStore();queryContext.beginTimestampMS = Date.now();for (const database of batchQueryDatabases) {- const isUnknownDatabase = database.uid === String(UNKNOWN_ID);if (abortController.signal.aborted) {// Once any one of the batch queries is aborted, don't go further// and mock an "Aborted" result for the rest queries.@@ -162,26 +166,42 @@ const useExecuteSQL = () => {});continue;}- const instance = isUnknownDatabase- ? params.connection.instance- : database.instance;- const dataSourceId =- instance === params.connection.instance- ? params.connection.dataSourceId ?? ""- : "";try {- const resultSet = await useSQLStore().queryReadonly(- {- name: database.name,- connectionDatabase: database.databaseName, // deprecated field, remove me later- dataSourceId: dataSourceId,- statement: params.statement,- limit: sqlEditorStore.resultRowsLimit,- explain: params.explain,- },- abortController.signal- );+ let resultSet: SQLResultSetV1;+ if (mode === "READONLY") {+ const isUnknownDatabase = database.uid === String(UNKNOWN_ID);+ const instance = isUnknownDatabase+ ? params.connection.instance+ : database.instance;+ const dataSourceId =+ instance === params.connection.instance+ ? params.connection.dataSourceId ?? ""+ : "";+ resultSet = await sqlStore.queryReadonly(+ {+ name: database.name,+ connectionDatabase: database.databaseName, // deprecated field, remove me later+ dataSourceId: dataSourceId,+ statement: params.statement,+ limit: sqlEditorStore.resultRowsLimit,+ explain: params.explain,+ timeout: undefined, // TODO: make this param configurable+ },+ abortController.signal+ );+ } else {+ resultSet = await sqlStore.executeStandard(+ {+ name: database.name,+ statement: params.statement,+ limit: sqlEditorStore.resultRowsLimit,+ timeout: undefined, // TODO: make this param configurable+ },+ abortController.signal+ );+ }+let adviceStatus: "SUCCESS" | "ERROR" | "WARNING" = "SUCCESS";let adviceNotifyMessage = "";for (const advice of resultSet.advices) {@@ -252,7 +272,7 @@ const useExecuteSQL = () => {};return {- executeReadonly,+ execute,};};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 08ae97ccbe..3b16af43bb 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2298,7 +2298,12 @@"rows-upper-limit": "reached the limit of query results","tab-mode": {"readonly": "Read-only",- "admin": "Admin"+ "admin": "Admin",+ "standard": "Standard",+ "description": {+ "standard": "Allow DDL and DML statements.",+ "readonly": "Allow SELECT, SHOW and SET statements."+ }},"close-sheet": "Close sheet","connect": "Connect",@@ -2362,7 +2367,11 @@},"n-per-page": "{n} / page","customize-tree-structure": "Customize tree structure",- "will-override-current-editing-statement": "Will override current editing statement."+ "will-override-current-editing-statement": "Will override current editing statement.",+ "standard-mode": {+ "self": "Standard mode"+ },+ "to-enable-standard-mode": "to enable the standard mode"},"schema-editor": {"self": "Schema Editor",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex b8382e7093..fc4e425f08 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2298,7 +2298,12 @@"rows-upper-limit": "se ha alcanzado el límite de resultados de la consulta","tab-mode": {"readonly": "Solo lectura",- "admin": "Admin"+ "admin": "Admin",+ "standard": "Estándar",+ "description": {+ "standard": "Permitir declaraciones DDL y DML.",+ "readonly": "Permitir declaraciones SELECT, SHOW y SET."+ }},"close-sheet": "Cerrar hoja","connect": "Conectar",@@ -2362,7 +2367,11 @@},"n-per-page": "{n} / página","customize-tree-structure": "Personalizar la estructura del árbol",- "will-override-current-editing-statement": "Anulará la declaración de edición actual."+ "will-override-current-editing-statement": "Anulará la declaración de edición actual.",+ "standard-mode": {+ "self": "Modo estandar"+ },+ "to-enable-standard-mode": "para habilitar el modo estándar"},"schema-editor": {"self": "Editor de esquema",@@ -3579,4 +3588,4 @@"self": "Última actualización"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 436ba7746b..4f49407338 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2298,7 +2298,12 @@"rows-upper-limit": "クエリ結果の数が上限に達しました","tab-mode": {"readonly": "読み取り専用",- "admin": "管理者"+ "admin": "管理者",+ "standard": "標準",+ "description": {+ "standard": "DDL および DML ステートメントを許可します。",+ "readonly": "SELECT、SHOW、SET ステートメントを許可します。"+ }},"close-sheet": "ワークシートを閉じる","connect": "接続する",@@ -2362,7 +2367,11 @@},"n-per-page": "{n} / ページ","customize-tree-structure": "ツリー構造をカスタマイズする",- "will-override-current-editing-statement": "現在の編集ステートメントをオーバーライドします。"+ "will-override-current-editing-statement": "現在の編集ステートメントをオーバーライドします。",+ "standard-mode": {+ "self": "標準モード"+ },+ "to-enable-standard-mode": "標準モードを有効にするには"},"schema-editor": {"self": "スキーマエディタ",@@ -3579,4 +3588,4 @@"self": "最後の更新"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 27f3577843..901d0c8c33 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2298,7 +2298,12 @@"rows-upper-limit": "到达查询结果条数上限","tab-mode": {"readonly": "只读",- "admin": "管理员"+ "admin": "管理员",+ "standard": "标准",+ "description": {+ "standard": "支持 DDL 和 DML 语句。",+ "readonly": "支持 SELECT、SHOW 和 SET 语句。"+ }},"close-sheet": "关闭工作表","connect": "连接",@@ -2362,7 +2367,11 @@},"n-per-page": "{n} / 页","customize-tree-structure": "自定义树结构",- "will-override-current-editing-statement": "将会覆盖当前的编辑中语句。"+ "will-override-current-editing-statement": "将会覆盖当前的编辑中语句。",+ "standard-mode": {+ "self": "标准模式"+ },+ "to-enable-standard-mode": "来开启标准模式"},"schema-editor": {"self": "Schema 编辑器",diff --git a/frontend/src/router/sqlEditor.ts b/frontend/src/router/sqlEditor.tsindex 90ce99e483..f91f72c1c5 100644--- a/frontend/src/router/sqlEditor.ts+++ b/frontend/src/router/sqlEditor.ts@@ -9,6 +9,7 @@ export const SQL_EDITOR_WORKSHEET_MODULE = "sql-editor.worksheet";export const SQL_EDITOR_DETAIL_MODULE_LEGACY = "sql-editor.legacy-detail";export const SQL_EDITOR_SHARE_MODULE_LEGACY = "sql-editor.legacy-share";export const SQL_EDITOR_SETTING_MODULE = "sql-editor.setting";+export const SQL_EDITOR_SETTING_GENERAL_MODULE = "sql-editor.setting.general";export const SQL_EDITOR_SETTING_INSTANCE_MODULE = "sql-editor.setting.instance";export const SQL_EDITOR_SETTING_ENVIRONMENT_MODULE ="sql-editor.setting.environment";@@ -74,6 +75,17 @@ const sqlEditorRoutes: RouteRecordRaw[] = [meta: { title: () => "Bytebase SQL Editor" },component: () => import("../views/sql-editor/SQLEditorSettingPage.vue"),children: [+ {+ path: "general",+ name: SQL_EDITOR_SETTING_GENERAL_MODULE,+ meta: {+ requiredWorkspacePermissionList: () => [+ "bb.settings.get",+ "bb.settings.set",+ ],+ },+ component: () => import("../views/sql-editor/Setting/General"),+ },{path: "instance",name: SQL_EDITOR_SETTING_INSTANCE_MODULE,diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.tsindex fbb2f98fb8..0ed700b029 100644--- a/frontend/src/store/modules/v1/setting.ts+++ b/frontend/src/store/modules/v1/setting.ts@@ -77,6 +77,7 @@ export const useSettingV1Store = defineStore("setting_v1", {},async fetchSettingList() {const { settings } = await settingServiceClient.listSettings({});+ // console.log(JSON.stringify(settings, null, " "));for (const setting of settings) {this.settingMapByName.set(setting.name, setting);}diff --git a/frontend/src/store/modules/v1/sql.ts b/frontend/src/store/modules/v1/sql.tsindex 310eb33fe8..2201fd7ee1 100644--- a/frontend/src/store/modules/v1/sql.ts+++ b/frontend/src/store/modules/v1/sql.ts@@ -9,6 +9,7 @@ import type {QueryRequest,Advice,GenerateRestoreSQLRequest,+ ExecuteRequest,} from "@/types/proto/v1/sql_service";import { Advice_Status } from "@/types/proto/v1/sql_service";import { extractGrpcErrorMessage } from "@/utils/grpcweb";@@ -69,22 +70,52 @@ export const useSQLStore = defineStore("sql", () => {}};+ const executeStandard = async (+ params: ExecuteRequest,+ signal: AbortSignal+ ): Promise<SQLResultSetV1> => {+ try {+ const response = await sqlServiceClient.execute(params, {+ // Skip global error handling since we will handle and display+ // errors manually.+ ignoredCodes: [Status.PERMISSION_DENIED],+ silent: true,+ signal,+ });++ return {+ error: "",+ allowExport: false, // TODO: should be judged by server-side+ ...response,+ };+ } catch (err) {+ return {+ error: extractGrpcErrorMessage(err),+ results: [],+ advices: getSqlReviewReports(err),+ allowExport: false,+ status: err instanceof ClientError ? err.code : Status.UNKNOWN,+ };+ }+ };+const exportData = async (params: ExportRequest) => {return await sqlServiceClient.export(params, {// Won't jump to 403 page when permission denied.ignoredCodes: [Status.PERMISSION_DENIED],});};-+const generateRestoreSQL = async (params: GenerateRestoreSQLRequest) => {return await sqlServiceClient.generateRestoreSQL(params, {// Won't jump to 403 page when permission denied.ignoredCodes: [Status.PERMISSION_DENIED],});- }+ };return {queryReadonly,+ executeStandard,exportData,generateRestoreSQL,};diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vueindex 86d58fd5d6..b309a97555 100644--- a/frontend/src/views/SettingWorkspaceGeneral.vue+++ b/frontend/src/views/SettingWorkspaceGeneral.vue@@ -5,7 +5,7 @@<SecuritySetting :allow-edit="allowEdit" /><AIAugmentationSetting :allow-edit="allowEdit" /><AnnouncementSetting :allow-edit="allowEdit" />- <DatabaseChangeModeSetting v-if="isDev()" :allow-edit="allowEdit" />+ <DatabaseChangeModeSetting :allow-edit="allowEdit" /></div></template>@@ -23,7 +23,6 @@ import {} from "@/components/GeneralSetting";import { useActuatorV1Store } from "@/store";import { useSettingV1Store } from "@/store/modules/v1/setting";-import { isDev } from "@/utils";defineProps<{allowEdit: boolean;diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsxindex 49aeadeea5..4c4dd90fda 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx@@ -310,7 +310,7 @@ const runQuery = async (statement: string) => {const tabStore = useSQLEditorTabStore();- const { executeReadonly } = useExecuteSQL();+ const { execute } = useExecuteSQL();const tab: CoreSQLEditorTab = {connection: {instance: database.instance,@@ -345,7 +345,7 @@ const runQuery = async ();}await nextTick();- executeReadonly({+ execute({statement,connection: { ...tab.connection },explain: false,diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vueindex 218672ac5c..3a9f87f3be 100644--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue@@ -49,6 +49,7 @@</span></NButton><ResultLimitSelect />+ <QueryModeSelect v-if="showQueryModeSelect" :disabled="isExecutingSQL" /></div><divclass="action-right gap-x-2 flex overflow-x-auto sm:overflow-x-hidden sm:justify-end items-center"@@ -124,6 +125,7 @@ import { keyboardShortcutStr } from "@/utils";import { useSQLEditorContext } from "../context";import AdminModeButton from "./AdminModeButton.vue";import QueryContextSettingPopover from "./QueryContextSettingPopover.vue";+import QueryModeSelect from "./QueryModeSelect.vue";import ResultLimitSelect from "./ResultLimitSelect.vue";import SharePopover from "./SharePopover.vue";@@ -140,7 +142,7 @@ const actuatorStore = useActuatorV1Store();const state = reactive<LocalState>({});const tabStore = useSQLEditorTabStore();const uiStateStore = useUIStateStore();-const { events } = useSQLEditorContext();+const { standardModeEnabled, events } = useSQLEditorContext();const containerRef = ref<HTMLDivElement>();const { width: containerWidth } = useElementSize(containerRef);const hasSharedSQLScriptFeature = featureToRef("bb.feature.shared-sql-script");@@ -245,6 +247,17 @@ const showQueryContextSettingPopover = computed(() => {);});+const showQueryModeSelect = computed(() => {+ const tab = currentTab.value;+ if (!tab) {+ return false;+ }+ if (!standardModeEnabled.value) {+ return false;+ }+ return tab.mode !== "ADMIN";+});+const handleRunQuery = () => {const tab = currentTab.value;if (!tab) {diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vueindex d78e1d6c15..7e4632804d 100644--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue@@ -5,36 +5,25 @@<p><i18n-t keypath="sql-editor.only-select-allowed"><template #select>- <strong>SELECT</strong>+ <strong+ ><code>SELECT</code>, <code>SHOW</code> and+ <code>SET</code></strong+ ></template></i18n-t></p>- <p>+ <p v-if="descriptions.action && descriptions.reaction"><i18n-t keypath="sql-editor.want-to-action"><template #want>- {{- isDDL- ? $t("database.edit-schema").toLowerCase()- : $t("database.change-data").toLowerCase()- }}+ {{ descriptions.want }}</template><template #action><strong>- {{- showActionButtons- ? isDDL- ? $t("database.edit-schema")- : $t("database.change-data")- : $t("sql-editor.admin-mode.self")- }}+ {{ descriptions.action }}</strong></template><template #reaction>- {{- showActionButtons- ? $t("sql-editor.and-submit-an-issue")- : $t("sql-editor.to-enable-admin-mode")- }}+ {{ descriptions.reaction }}</template></i18n-t></p>@@ -43,7 +32,7 @@<div class="execute-hint-content mt-4 flex justify-between"><div- v-if="showActionButtons"+ v-if="actions.action && actions.admin"class="flex justify-start items-center space-x-2"><AdminModeButton @enter="$emit('close')" />@@ -51,11 +40,18 @@<div class="flex flex-1 justify-end items-center space-x-2"><NButton @click="handleClose">{{ $t("common.close") }}</NButton><NButton- v-if="showActionButtons"+ v-if="actions.action"type="primary"- @click="gotoCreateIssue"+ @click="handleClickActionButton">- {{ isDDL ? $t("database.edit-schema") : $t("database.change-data") }}+ <template v-if="actions.action === 'CREATE_ISSUE'">+ {{+ isDDL ? $t("database.edit-schema") : $t("database.change-data")+ }}+ </template>+ <template v-if="actions.action === 'STANDARD_MODE'">+ {{ $t("sql-editor.standard-mode.self") }}+ </template></NButton><AdminModeButton v-else @enter="$emit('close')" /></div>@@ -74,10 +70,12 @@ import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import {pushNotification,useActuatorV1Store,+ useCurrentUserV1,useDatabaseV1Store,useSQLEditorTabStore,} from "@/store";-import { extractProjectResourceName } from "@/utils";+import { extractProjectResourceName, hasWorkspacePermissionV2 } from "@/utils";+import { useSQLEditorContext } from "../context";import AdminModeButton from "./AdminModeButton.vue";const emit = defineEmits<{@@ -89,7 +87,9 @@ const DMLIssueTemplate = "bb.issue.database.data.update";const router = useRouter();const { t } = useI18n();+const me = useCurrentUserV1();const tabStore = useSQLEditorTabStore();+const { standardModeEnabled } = useSQLEditorContext();const { pageMode } = storeToRefs(useActuatorV1Store());const statement = computed(() => {@@ -102,7 +102,50 @@ const isDDL = computedAsync(async () => {return data !== null ? isDDLStatement(data, "some") : false;}, false);-const showActionButtons = computed(() => pageMode.value === "BUNDLED");+const actions = computed(() => {+ type Actions = {+ admin: boolean;+ action: "STANDARD_MODE" | "CREATE_ISSUE" | undefined;+ };+ const actions: Actions = {+ admin: false,+ action: undefined,+ };+ if (hasWorkspacePermissionV2(me.value, "bb.instances.adminExecute")) {+ actions.admin = true;+ }+ if (standardModeEnabled.value) {+ actions.action = "STANDARD_MODE";+ } else if (pageMode.value === "BUNDLED") {+ actions.action = "CREATE_ISSUE";+ }++ return actions;+});++const descriptions = computed(() => {+ const descriptions = {+ want: isDDL.value+ ? t("database.edit-schema").toLowerCase()+ : t("database.change-data").toLowerCase(),+ action: "",+ reaction: "",+ };+ const { admin, action } = actions.value;+ if (action === "CREATE_ISSUE") {+ descriptions.action = isDDL+ ? 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");+ }+ return descriptions;+});const handleClose = () => {emit("close");@@ -139,4 +182,28 @@ const gotoCreateIssue = () => {},});};++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;+ }+};</script>diff --git a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vueindex 9638835304..f4eb71e221 100644--- a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue+++ b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue@@ -103,7 +103,9 @@ const renderLabel: SelectRenderLabel = (option) => {{class: "w-full",},- children+ {+ default: () => children,+ });};diff --git a/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vue b/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vuenew file mode 100644index 0000000000..f8d70cff16--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/QueryModeSelect.vue@@ -0,0 +1,51 @@+<template>+ <NPopover placement="bottom" trigger="click">+ <template #trigger>+ <NButton size="small" :disabled="disabled">+ {{ $t(`sql-editor.tab-mode.${tab.mode.toLowerCase()}`) }}+ </NButton>+ </template>+ <div class="flex flex-col gap-2">+ <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, 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.vueindex 34507fe77f..d777acd177 100644--- a/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue@@ -1,8 +1,8 @@<template><NPopover v-if="showReadonlyDatasourceHint" trigger="hover"><template #trigger>- <heroicons-outline:information-circle- class="h-5 w-5 flex-shrink-0 text-info"+ <TriangleAlertIcon+ class="h-4 w-4 flex-shrink-0 text-info"v-bind="$attrs"/></template>@@ -26,12 +26,16 @@</template><script setup lang="ts">+import { TriangleAlertIcon } from "lucide-vue-next";import { computed } from "vue";+import { useRouter } from "vue-router";+import { SQL_EDITOR_SETTING_INSTANCE_MODULE } from "@/router/sqlEditor";import { useCurrentUserV1, useSQLEditorTabStore } from "@/store";import type { ComposedInstance } from "@/types";import { UNKNOWN_ID } from "@/types";import { DataSourceType } from "@/types/proto/v1/instance_service";import { hasWorkspacePermissionV2 } from "@/utils";+import { useSidebarItems as useSettingItems } from "../Setting/Sidebar";const props = defineProps<{instance: ComposedInstance;@@ -39,10 +43,8 @@ const props = defineProps<{const tabStore = useSQLEditorTabStore();const me = useCurrentUserV1();--const isAdminMode = computed(() => {- return tabStore.currentTab?.mode === "ADMIN";-});+const router = useRouter();+const { itemList: settingItemList } = useSettingItems();const allowManageInstance = computed(() => {return hasWorkspacePermissionV2(me.value, "bb.instances.update");@@ -58,13 +60,25 @@ const hasReadonlyDataSource = computed(() => {const showReadonlyDatasourceHint = computed(() => {return (- !isAdminMode.value &&+ tabStore.currentTab?.mode === "READONLY" &&props.instance.uid !== String(UNKNOWN_ID) &&!hasReadonlyDataSource.value);});const gotoInstanceDetailPage = () => {- window.open(`/${props.instance.name}`);+ const { name } = props.instance;+ if (+ settingItemList.value.findIndex(+ (item) => item.name === SQL_EDITOR_SETTING_INSTANCE_MODULE+ )+ ) {+ router.push({+ name: SQL_EDITOR_SETTING_INSTANCE_MODULE,+ hash: `#${name}`,+ });+ } else {+ window.open(`/${props.instance.name}`);+ }};</script>diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex d7b4ae6bdc..3bab44a4f6 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -35,7 +35,7 @@<script lang="ts" setup>import { storeToRefs } from "pinia";-import { defineAsyncComponent } from "vue";+import { defineAsyncComponent, watch } from "vue";import { useExecuteSQL } from "@/composables/useExecuteSQL";import { AIChatToSQL } from "@/plugins/ai";import { useInstanceV1Store, usePageMode, useSQLEditorTabStore } from "@/store";@@ -53,13 +53,13 @@ const SQLEditor = defineAsyncComponent(() => import("./SQLEditor.vue"));const tabStore = useSQLEditorTabStore();const { currentTab: tab, isDisconnected } = storeToRefs(tabStore);-const { showAIChatBox } = useSQLEditorContext();+const { showAIChatBox, standardModeEnabled } = useSQLEditorContext();const pageMode = usePageMode();-const { executeReadonly } = useExecuteSQL();+const { execute } = useExecuteSQL();const handleExecute = (params: SQLEditorQueryParams) => {- executeReadonly(params);+ execute(params);};const handleApplyStatement = async (@@ -83,4 +83,19 @@ const handleApplyStatement = async (});}};++watch(+ [() => tab.value, standardModeEnabled],+ ([tab, standardModeEnabled]) => {+ if (!tab) return;+ // Fallback to READONLY mode if standard mode is not allowed.+ if (!standardModeEnabled && tab.mode === "STANDARD") {+ tab.mode = "READONLY";+ }+ },+ {+ immediate: true,+ deep: false,+ }+);</script>diff --git a/frontend/src/views/sql-editor/Setting/General/General.vue b/frontend/src/views/sql-editor/Setting/General/General.vuenew file mode 100644index 0000000000..23db8d5891--- /dev/null+++ b/frontend/src/views/sql-editor/Setting/General/General.vue@@ -0,0 +1,24 @@+<template>+ <div+ class="w-full flex flex-col gap-4 py-4 px-4 divide-y divide-block-border overflow-y-auto"+ >+ <DatabaseChangeModeSetting :allow-edit="allowEdit" />+ <AIAugmentationSetting :allow-edit="allowEdit" />+ </div>+</template>++<script lang="ts" setup>+import { computed } from "vue";+import {+ AIAugmentationSetting,+ DatabaseChangeModeSetting,+} from "@/components/GeneralSetting";+import { useCurrentUserV1 } from "@/store";+import { hasWorkspacePermissionV2 } from "@/utils";++const me = useCurrentUserV1();++const allowEdit = computed((): boolean => {+ return hasWorkspacePermissionV2(me.value, "bb.settings.set");+});+</script>diff --git a/frontend/src/views/sql-editor/Setting/General/index.ts b/frontend/src/views/sql-editor/Setting/General/index.tsnew file mode 100644index 0000000000..d4e18409b0--- /dev/null+++ b/frontend/src/views/sql-editor/Setting/General/index.ts@@ -0,0 +1,3 @@+import SQLEditorSettingGeneral from "./General.vue";++export default SQLEditorSettingGeneral;diff --git a/frontend/src/views/sql-editor/Setting/Sidebar/common.ts b/frontend/src/views/sql-editor/Setting/Sidebar/common.tsindex 80c0dd1418..04152e7034 100644--- a/frontend/src/views/sql-editor/Setting/Sidebar/common.ts+++ b/frontend/src/views/sql-editor/Setting/Sidebar/common.ts@@ -1,4 +1,5 @@import {+ BuildingIcon,GalleryHorizontalEndIcon,LayersIcon,SquareStackIcon,@@ -8,6 +9,7 @@ import { useI18n } from "vue-i18n";import { useRoute, type RouteRecordRaw } from "vue-router";import type { SidebarItem } from "@/components/CommonSidebar.vue";import sqlEditorRoutes, {+ SQL_EDITOR_SETTING_GENERAL_MODULE,SQL_EDITOR_SETTING_ENVIRONMENT_MODULE,SQL_EDITOR_SETTING_INSTANCE_MODULE,SQL_EDITOR_SETTING_PROJECT_MODULE,@@ -93,6 +95,12 @@ export const useSidebarItems = () => {const itemList = computed((): SidebarItem[] => {const sidebarList: SidebarItem[] = [+ {+ title: t("settings.sidebar.general"),+ icon: h(BuildingIcon),+ name: SQL_EDITOR_SETTING_GENERAL_MODULE,+ type: "route",+ },{title: t("common.instances"),icon: h(LayersIcon),diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.tsindex c04a6dd6ac..02e3277cb5 100644--- a/frontend/src/views/sql-editor/context.ts+++ b/frontend/src/views/sql-editor/context.ts@@ -1,8 +1,12 @@import Emittery from "emittery";import type { InjectionKey, Ref } from "vue";-import { inject, provide, ref } from "vue";-import { useSQLEditorStore } from "@/store";+import { computed, inject, provide, ref } from "vue";+import {+ useSQLEditorStore,+ useSettingV1Store,+} 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";@@ -37,6 +41,7 @@ export type SQLEditorContext = {}| undefined>;+ standardModeEnabled: Ref<boolean>;events: SQLEditorEvents;@@ -59,6 +64,12 @@ 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) {