Skip to content

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

chore: fix batch query issues (#8595)

boojacka3995de33723
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index b715266ac4..2e80e2da66 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -9,6 +9,7 @@ import {
useSQLEditorStore,
useCurrentUserV1,
useDatabaseV1Store,
+ useCurrentUserIamPolicy,
} from "@/store";
import {
ComposedDatabase,
@@ -30,6 +31,7 @@ const useExecuteSQL = () => {
const databaseStore = useDatabaseV1Store();
const tabStore = useTabStore();
const sqlEditorStore = useSQLEditorStore();
+ const currentUserIamPolicy = useCurrentUserIamPolicy();
const notify = (
type: BBNotificationStyle,
@@ -110,9 +112,18 @@ const useExecuteSQL = () => {
batchQueryContext &&
batchQueryContext.selectedLabels.length > 0
) {
- const databases = useDatabaseV1Store().databaseListByProject(
- selectedDatabase.project
- );
+ const databases = useDatabaseV1Store()
+ .databaseListByProject(selectedDatabase.project)
+ // Don't show the currently selected database.
+ .filter((db) => db.uid !== selectedDatabase.uid)
+ // Only show databases with same engine.
+ .filter(
+ (db) =>
+ db.instanceEntity.engine === selectedDatabase.instanceEntity.engine
+ )
+ // Only show databases that the user has permission to query.
+ .filter((db) => currentUserIamPolicy.allowToQueryDatabaseV1(db));
+
for (const database of databases) {
if (database.name === selectedDatabase.name) {
continue;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 42f55da341..742cd47185 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2054,7 +2054,10 @@
},
"filter-by-name": "Filter by name",
"batch-query": {
- "description": "Batch query additional databases with the same label values."
+ "batch": "Batch",
+ "database-labels": "{database} labels",
+ "database-has-no-label": "{database} has no label",
+ "description": "Batch query {count} additional databases with the same label values."
}
},
"schema-editor": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index c1a430d7b7..778dc2cd5a 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2050,6 +2050,9 @@
},
"filter-by-name": "Filtrar por nombre",
"batch-query": {
+ "batch": "Lote",
+ "database-labels": "Etiquetas de {database}",
+ "database-has-no-label": "{database} no tiene etiquetas",
"description": "Consulta por lotes bases de datos adicionales con los mismos valores de etiqueta."
}
},
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 4719d873f1..df15eec18b 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2049,6 +2049,9 @@
},
"filter-by-name": "根据名称过滤",
"batch-query": {
+ "batch": "批量",
+ "database-labels": "{database} 标签",
+ "database-has-no-label": "{database} 没有标签",
"description": "批量查询具有相同标签值的其他数据库。"
}
},
diff --git a/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue b/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue
index da4073ed19..9eb9711f21 100644
--- a/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue
@@ -10,42 +10,60 @@
@click="handleTriggerClick"
>
<div
- class="!ml-2 min-w-[1.5rem] h-6 p-1 flex flex-row justify-center items-center gap-1 cursor-pointer rounded hover:opacity-80"
+ class="!ml-2 w-auto h-6 px-2 border border-gray-400 flex flex-row justify-center items-center gap-1 cursor-pointer rounded hover:opacity-80"
:class="
- selectedLabelsValue.length > 0 && hasBatchQueryFeature
- ? 'text-accent bg-blue-50 shadow'
+ matchedDatabases.length > 0 && hasBatchQueryFeature
+ ? 'text-accent bg-blue-50 shadow !border-accent'
: 'text-gray-600'
"
>
- <Layers class="w-4 h-auto" />
- <span v-if="selectedLabelsValue.length > 0"
- >({{ selectedLabelsValue.length }})</span
- >
+ <span>{{ $t("sql-editor.batch-query.batch") }}</span>
+ <span v-if="matchedDatabases.length > 0">
+ ({{ matchedDatabases.length }})
+ </span>
+ <FeatureBadge feature="bb.feature.batch-query" />
</div>
- <FeatureBadge feature="bb.feature.batch-query" />
</div>
</template>
- <div class="w-128">
- <p class="text-gray-500 mb-1">
- {{ $t("sql-editor.batch-query.description") }}
+ <div class="w-128 max-h-128 overflow-y-auto p-1 pb-2">
+ <p class="text-gray-500 mb-1 w-full leading-4">
+ <span class="mr-1">{{
+ $t("sql-editor.batch-query.description", {
+ count: matchedDatabases.length,
+ })
+ }}</span>
<LearnMoreLink
url="https://www.bytebase.com/docs/sql-editor/batch-query?source=console"
- class="ml-1 text-sm"
+ class="text-sm"
/>
</p>
- <div class="w-full grid grid-cols-3 gap-2 py-1">
- <div class="col-span-1">
+ <div class="w-full flex flex-col justify-start items-start">
+ <div class="w-full">
+ <p class="font-medium">
+ {{
+ labels.length > 0
+ ? $t("sql-editor.batch-query.database-labels", {
+ database: selectedDatabase.databaseName,
+ })
+ : $t("sql-editor.batch-query.database-has-no-label", {
+ database: selectedDatabase.databaseName,
+ })
+ }}
+ </p>
<NCheckboxGroup v-model:value="selectedLabelsValue">
- <NCheckbox
- v-for="label in labels"
- :key="`${label.key}-${label.value}`"
- :value="`${label.key}-${label.value}`"
- :label="`${getFormattedLabelKey(label.key)}:${label.value}`"
- >
- </NCheckbox>
+ <NSpace class="flex">
+ <NCheckbox
+ v-for="label in labels"
+ :key="`${label.key}-${label.value}`"
+ :value="`${label.key}-${label.value}`"
+ :label="`${getFormattedLabelKey(label.key)}:${label.value}`"
+ >
+ </NCheckbox>
+ </NSpace>
</NCheckboxGroup>
</div>
- <div class="col-span-2">
+ <NDivider class="!my-3" />
+ <div class="w-full">
<MatchedDatabaseView
:hide-title="true"
:matched-database-list="matchedDatabases"
@@ -64,9 +82,14 @@
</template>
<script lang="ts" setup>
-import { upperFirst } from "lodash-es";
-import { Layers } from "lucide-vue-next";
-import { NCheckboxGroup, NCheckbox, NPopover } from "naive-ui";
+import { isEqual, upperFirst } from "lodash-es";
+import {
+ NCheckboxGroup,
+ NCheckbox,
+ NPopover,
+ NSpace,
+ NDivider,
+} from "naive-ui";
import { computed, reactive, ref, watch } from "vue";
import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
import {
@@ -111,17 +134,23 @@ const filteredDatabaseList = computed(() => {
.filter((db) => db.uid !== selectedDatabase.value.uid)
// Only show databases that the user has permission to query.
.filter((db) => currentUserIamPolicy.allowToQueryDatabaseV1(db))
- // Only show databases that have at least one label.
- .filter((db) => getFilteredDatabaseLabels(db.labels).length > 0)
+ // Only show databases with same engine.
+ .filter(
+ (db) =>
+ db.instanceEntity.engine ===
+ selectedDatabase.value.instanceEntity.engine
+ )
+ // Only show databases that have at least one same label.
+ .filter((db) =>
+ getFilteredDatabaseLabels(db.labels).some((label) =>
+ labels.value.find((raw) => isEqual(raw, label))
+ )
+ )
);
});
const labels = computed(() => {
- return filteredDatabaseList.value
- .map((db) => {
- return getFilteredDatabaseLabels(db.labels);
- })
- .flat();
+ return getFilteredDatabaseLabels(selectedDatabase.value.labels);
});
const handleTriggerClick = () => {
@@ -174,7 +203,7 @@ const getFormattedLabelKey = (labelKey: string) => {
if (labelKey.startsWith("bb.")) {
return upperFirst(labelKey.substring(3));
}
- return upperFirst(labelKey);
+ return labelKey;
};
watch(selectedLabelsValue, () => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue
index a49eb21d58..586aec0105 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue
@@ -79,7 +79,6 @@ import { InstanceV1EngineIcon } from "@/components/v2";
import { useTabStore, useDatabaseV1ByUID, useInstanceV1ByUID } from "@/store";
import { TabMode, UNKNOWN_ID } from "@/types";
import { EnvironmentTier } from "@/types/proto/v1/environment_service";
-import { TenantMode } from "@/types/proto/v1/project_service";
import BatchQueryDatabasesSelector from "./BatchQueryDatabasesSelector.vue";
import ReadonlyDatasourceHint from "./ReadonlyDatasourceHint.vue";
@@ -95,8 +94,6 @@ const { database: selectedDatabaseV1 } = useDatabaseV1ByUID(
computed(() => String(connection.value.databaseId))
);
-const selectedProject = computed(() => selectedDatabaseV1.value.projectEntity);
-
const selectedEnvironment = computed(() => {
return connection.value.databaseId === `${UNKNOWN_ID}`
? selectedInstance.value.environmentEntity
@@ -113,7 +110,8 @@ const isProductionEnvironment = computed(() => {
const showBatchQuerySelector = computed(() => {
return (
- selectedProject.value.tenantMode === TenantMode.TENANT_MODE_ENABLED &&
+ // Only show entry when user selected a database.
+ selectedDatabaseV1.value.uid !== String(UNKNOWN_ID) &&
// TODO(steven): implement batch query in admin mode.
currentTab.value.mode !== TabMode.Admin
);
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index 1eeb92e37a..7d5d104cba 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -1,7 +1,7 @@
<template>
<NConfigProvider
v-bind="naiveUIConfig"
- class="relative flex flex-col justify-start items-start p-2 pb-1"
+ class="relative flex flex-col justify-start items-start p-2 pb-1 overflow-y-auto"
:class="dark && 'dark bg-dark-bg'"
>
<template v-if="executeParams && resultSet && !showPlaceholder">
diff --git a/frontend/src/views/sql-editor/ResultPanel/ResultPanel.vue b/frontend/src/views/sql-editor/ResultPanel/ResultPanel.vue
index e441077063..10c432cbfb 100644
--- a/frontend/src/views/sql-editor/ResultPanel/ResultPanel.vue
+++ b/frontend/src/views/sql-editor/ResultPanel/ResultPanel.vue
@@ -1,17 +1,24 @@
<template>
<div
- class="absolute inset-0 flex flex-col justify-center items-center z-10"
+ class="absolute inset-0 flex flex-col justify-start items-start z-10"
:class="loading && 'bg-white/80 dark:bg-black/80'"
>
<template v-if="loading">
- <BBSpin />
- {{ $t("sql-editor.loading-data") }}
+ <div class="w-full h-full flex flex-col justify-center items-center">
+ <BBSpin />
+ {{ $t("sql-editor.loading-data") }}
+ </div>
</template>
<template v-else-if="!selectedResultSet">
- {{ $t("sql-editor.table-empty-placeholder") }}
+ <div class="w-full h-full flex flex-col justify-center items-center">
+ <span>{{ $t("sql-editor.table-empty-placeholder") }}</span>
+ </div>
</template>
<template v-else>
- <div class="w-full flex flex-row justify-start items-center p-2 gap-2">
+ <div
+ v-if="databases.length > 1"
+ class="w-full flex flex-row justify-start items-center p-2 pb-0 gap-2 shrink-0"
+ >
<NTooltip
v-for="database in databases"
:key="database.name"
@@ -43,7 +50,7 @@
</NTooltip>
</div>
<ResultViewV1
- class="w-full h-full"
+ class="w-full h-auto grow"
:execute-params="executeParams"
:result-set="selectedResultSet"
/>