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): inform user that we are in a danger zone (#3147)
Liu Jif66d35dd120d
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 9064078c45..6d1f3794f8 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1321,7 +1321,7 @@"sql-execute-in-protected-environment": "The SQL statement below will be executed in a protected environment.","rows-upper-limit": "reached the limit of query results","tab-mode": {- "readonly": "Readonly",+ "readonly": "Read-only","admin": "Admin"}},diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex bc7c3c3321..c460aedba7 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -74,6 +74,7 @@ import { scrollIntoViewIfNeeded } from "@/bbkit/BBUtil";import InstanceEngineIcon from "@/components/InstanceEngineIcon.vue";import HeroiconsOutlineDatabase from "~icons/heroicons-outline/database";import HeroiconsOutlineTable from "~icons/heroicons-outline/table";+import ProtectedEnvironmentIcon from "@/components/Environment/ProtectedEnvironmentIcon.vue";type Position = {x: number;@@ -212,9 +213,17 @@ const renderPrefix = ({ option }: { option: ConnectionAtom }) => {if (option.type === "instance") {const instanceId = option.id;const instance = instanceStore.getInstanceById(instanceId);- return h(InstanceEngineIcon, {- instance,- });+ const children = [+ h(InstanceEngineIcon, {+ instance,+ }),+ h(ProtectedEnvironmentIcon, {+ environment: instance.environment,+ class: "w-4 h-4",+ }),+ ];++ return h("span", { class: "flex items-center gap-x-1" }, children);} else if (option.type === "database") {return h(HeroiconsOutlineDatabase, {class: "w-4 h-4",diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vueindex f51c625e1e..1b0554e81a 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue@@ -22,90 +22,6 @@</NButton></div><div class="action-right space-x-2 flex justify-end items-center">- <NPopover- v-if="selectedInstance.id !== UNKNOWN_ID && !hasReadonlyDataSource"- trigger="hover"- >- <template #trigger>- <heroicons-outline:exclamation- class="h-6 w-6 text-yellow-400 flex-shrink-0 mr-2"- />- </template>- <p class="py-1">- {{ $t("instance.no-read-only-data-source-warn") }}- <span- class="underline text-accent cursor-pointer hover:opacity-80"- @click="gotoInstanceDetailPage"- >- {{ $t("sql-editor.create-read-only-data-source") }}- </span>- </p>- </NPopover>-- <NPopover trigger="hover" placement="bottom-center" :show-arrow="false">- <template #trigger>- <label class="flex items-center text-sm space-x-1">- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="ml-2">{{ selectedInstance.environment.name }}</span>- <ProtectedEnvironmentIcon- :environment="selectedInstance.environment"- class="ml-1"- />- </div>- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="mx-2">/</span>- <InstanceEngineIcon :instance="selectedInstance" show-status />- <span class="ml-2">{{ selectedInstance.name }}</span>- </div>- <div- v-if="selectedDatabase.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="mx-2">/</span>- <heroicons-outline:database />- <span class="ml-2">{{ selectedDatabase.name }}</span>- </div>- </label>- </template>- <section>- <div class="space-y-2">- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.environment") }}</h1>- <span class="flex items-center">- {{ selectedInstance.environment.name }}- <ProtectedEnvironmentIcon- :environment="selectedInstance.environment"- class="ml-1"- />- </span>- </div>- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.instance") }}</h1>- <span>{{ selectedInstance.name }}</span>- </div>- <div- v-if="selectedDatabase.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.database") }}</h1>- <span>{{ selectedDatabase.name }}</span>- </div>- </div>- </section>- </NPopover>-<TabModeSelect /><NButton@@ -139,26 +55,21 @@<script lang="ts" setup>import { computed, defineEmits } from "vue";-import { useRouter } from "vue-router";import { useExecuteSQL } from "@/composables/useExecuteSQL";import {useInstanceStore,useTabStore,useSQLEditorStore,useInstanceById,- useDatabaseById,} from "@/store";import { UNKNOWN_ID } from "@/types";-import { instanceSlug } from "@/utils/slug";import SharePopover from "./SharePopover.vue";-import ProtectedEnvironmentIcon from "@/components/Environment/ProtectedEnvironmentIcon.vue";import TabModeSelect from "./TabModeSelect.vue";const emit = defineEmits<{(e: "save-sheet", content?: string): void;}>();-const router = useRouter();const instanceStore = useInstanceStore();const tabStore = useTabStore();const sqlEditorStore = useSQLEditorStore();@@ -175,18 +86,6 @@ const selectedInstance = useInstanceById(const selectedInstanceEngine = computed(() => {return instanceStore.formatEngine(selectedInstance.value);});-const selectedDatabase = useDatabaseById(- computed(() => connection.value.databaseId)-);--const hasReadonlyDataSource = computed(() => {- for (const ds of selectedInstance.value.dataSourceList) {- if (ds.type === "RO") {- return true;- }- }- return false;-});const allowSave = computed(() => {if (isEmptyStatement.value) {@@ -225,16 +124,6 @@ const handleExplainQuery = () => {);};-const gotoInstanceDetailPage = () => {- const route = router.resolve({- name: "workspace.instance.detail",- params: {- instanceSlug: instanceSlug(selectedInstance.value),- },- });- window.open(route.href);-};-const handleFormatSQL = () => {sqlEditorStore.setShouldFormatContent(true);};diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex 9c77b61afc..49525c46b3 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -3,10 +3,105 @@<EditorAction @save-sheet="handleSaveSheet" /><div- v-if="isProtectedEnvironment"- class="w-full py-1 px-4 bg-warning text-white"+ v-if="!tabStore.isDisconnected"+ class="w-full py-1 px-4 flex justify-between items-center border-b"+ :class="[isProtectedEnvironment && 'bg-yellow-50']">- {{ $t("sql-editor.sql-execute-in-protected-environment") }}+ <div :class="[isProtectedEnvironment ? 'text-yellow-700' : 'text-main']">+ <template v-if="isProtectedEnvironment">+ {{ $t("sql-editor.sql-execute-in-protected-environment") }}+ </template>+ </div>++ <div class="action-right flex justify-end items-center">+ <NPopover+ v-if="selectedInstance.id !== UNKNOWN_ID && !hasReadonlyDataSource"+ trigger="hover"+ >+ <template #trigger>+ <heroicons-outline:exclamation+ class="h-6 w-6 flex-shrink-0 mr-2"+ :class="[+ isProtectedEnvironment ? 'text-yellow-500' : 'text-yellow-500',+ ]"+ />+ </template>+ <p class="py-1">+ {{ $t("instance.no-read-only-data-source-warn") }}+ <span+ class="underline text-accent cursor-pointer hover:opacity-80"+ @click="gotoInstanceDetailPage"+ >+ {{ $t("sql-editor.create-read-only-data-source") }}+ </span>+ </p>+ </NPopover>++ <NPopover trigger="hover" placement="bottom" :show-arrow="false">+ <template #trigger>+ <label class="flex items-center text-sm space-x-1">+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="">{{ selectedInstance.environment.name }}</span>+ <ProtectedEnvironmentIcon+ :environment="selectedInstance.environment"+ class="ml-1"+ :class="[isProtectedEnvironment && '~!text-yellow-700']"+ />+ </div>+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="mx-2">/</span>+ <InstanceEngineIcon :instance="selectedInstance" show-status />+ <span class="ml-2">{{ selectedInstance.name }}</span>+ </div>+ <div+ v-if="selectedDatabase.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="mx-2">/</span>+ <heroicons-outline:database />+ <span class="ml-2">{{ selectedDatabase.name }}</span>+ </div>+ </label>+ </template>+ <section>+ <div class="space-y-2">+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.environment") }}</h1>+ <span class="flex items-center">+ {{ selectedInstance.environment.name }}+ <ProtectedEnvironmentIcon+ :environment="selectedInstance.environment"+ class="ml-1"+ />+ </span>+ </div>+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.instance") }}</h1>+ <span>{{ selectedInstance.name }}</span>+ </div>+ <div+ v-if="selectedDatabase.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.database") }}</h1>+ <span>{{ selectedDatabase.name }}</span>+ </div>+ </div>+ </section>+ </NPopover>+ </div></div><template v-if="!tabStore.isDisconnected">@@ -35,13 +130,16 @@<script lang="ts" setup>import { computed, ref } from "vue";+import { NPopover } from "naive-ui";+import { useRouter } from "vue-router";import {useTabStore,useSQLEditorStore,useSheetStore,- useInstanceStore,useDatabaseStore,+ useInstanceById,+ useDatabaseById,} from "@/store";import { defaultTabName } from "@/utils/tab";import EditorAction from "./EditorAction.vue";@@ -51,21 +149,48 @@ import ConnectionHolder from "./ConnectionHolder.vue";import SaveSheetModal from "./SaveSheetModal.vue";import type { SheetUpsert } from "@/types";import { UNKNOWN_ID } from "@/types";+import { instanceSlug } from "@/utils";+const router = useRouter();const tabStore = useTabStore();const sqlEditorStore = useSQLEditorStore();const sheetStore = useSheetStore();-const instanceStore = useInstanceStore();const databaseStore = useDatabaseStore();const isShowSaveSheetModal = ref(false);+const connection = computed(() => tabStore.currentTab.connection);++const selectedInstance = useInstanceById(+ computed(() => connection.value.instanceId)+);+const selectedDatabase = useDatabaseById(+ computed(() => connection.value.databaseId)+);const isProtectedEnvironment = computed(() => {- const { instanceId } = tabStore.currentTab.connection;- const instance = instanceStore.getInstanceById(instanceId);+ const instance = selectedInstance.value;return instance.environment.tier === "PROTECTED";});+const hasReadonlyDataSource = computed(() => {+ for (const ds of selectedInstance.value.dataSourceList) {+ if (ds.type === "RO") {+ return true;+ }+ }+ return false;+});++const gotoInstanceDetailPage = () => {+ const route = router.resolve({+ name: "workspace.instance.detail",+ params: {+ instanceSlug: instanceSlug(selectedInstance.value),+ },+ });+ window.open(route.href);+};+const allowSave = computed((): boolean => {const tab = tabStore.currentTab;if (tab.statement === "") {diff --git a/frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vue b/frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vueindex 3b80c5c5a3..27f220478b 100644--- a/frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vue+++ b/frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vue@@ -3,14 +3,16 @@v-model:value="tabStore.currentTab.mode":options="tabModeOptions":consistent-menu-width="false"+ :render-label="renderLabel"@update:value="onUpdate"/></template><script lang="ts" setup>-import { computed } from "vue";+import { computed, h } from "vue";import { SelectOption } from "naive-ui";import { useI18n } from "vue-i18n";+import WrenchIcon from "~icons/heroicons-outline/wrench";import { TabMode } from "@/types";import { useCurrentUser, useTabStore } from "@/store";@@ -38,6 +40,22 @@ const tabModeOptions = computed((): SelectOption[] => {];});+const renderLabel = (option: SelectOption) => {+ if (option.value === TabMode.Admin) {+ return h(+ "span",+ {+ class: "flex items-center gap-x-1 text-error",+ },+ [+ h(WrenchIcon, { class: "h-4 w-4 " }),+ h("span", {}, String(option.label)),+ ]+ );+ }+ return option.label;+};+const onUpdate = () => {tabStore.currentTab.isSaved = false;};