Skip to content

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

chore: batch sync instances (#8842)

ecmadao85e4368a6cd2
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 7436999a4a..c75fd57953 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -1,10 +1,5 @@
<template>
<div class="space-y-2">
- <DatabaseOperations
- v-if="selectedDatabases.length > 0"
- :databases="selectedDatabases"
- @dismiss="state.selectedDatabaseIds.clear()"
- />
<div
class="text-lg font-medium leading-7 text-main flex items-center justify-between"
>
@@ -34,6 +29,12 @@
</NInputGroup>
</div>
+ <DatabaseOperations
+ v-if="selectedDatabases.length > 0"
+ :databases="selectedDatabases"
+ @dismiss="state.selectedDatabaseIds.clear()"
+ />
+
<template v-if="databaseList.length > 0">
<DatabaseV1Table
mode="PROJECT"
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue
index 848e2854a7..461a3a12be 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue
@@ -99,7 +99,7 @@
:page-size="table.getState().pagination.pageSize"
:show-quick-jumper="true"
@update-page="handleChangePage"
- @update-page-size="(ps) => table.setPageSize(ps)"
+ @update-page-size="table.setPageSize($event)"
/>
</div>
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue
new file mode 100644
index 0000000000..0624e004a9
--- /dev/null
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue
@@ -0,0 +1,96 @@
+<template>
+ <div
+ v-bind="$attrs"
+ class="flex items-center bg-blue-100 py-3 px-2 text-main"
+ >
+ <button
+ class="w-7 h-7 p-1 mr-3 rounded cursor-pointer"
+ @click.prevent="$emit('dismiss')"
+ >
+ <heroicons-outline:x class="w-5 h-5" />
+ </button>
+ {{
+ $t("instance.selected-n-instances", {
+ n: instanceList.length,
+ })
+ }}
+ <div class="flex items-center gap-x-4 text-sm ml-5 text-accent">
+ <template v-for="action in actions" :key="action.text">
+ <button
+ :disabled="action.disabled"
+ class="flex items-center gap-x-1 hover:text-accent-hover disabled:text-control-light disabled:cursor-not-allowed"
+ @click="action.click"
+ >
+ <component :is="action.icon" class="h-4 w-4" />
+ {{ action.text }}
+ </button>
+ </template>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed, h, VNode, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import RefreshIcon from "~icons/heroicons-outline/refresh";
+import { useInstanceV1Store, pushNotification } from "@/store";
+import { ComposedInstance } from "@/types";
+
+interface Action {
+ icon: VNode;
+ text: string;
+ disabled: boolean;
+ click: () => void;
+}
+
+interface LocalState {
+ loading: boolean;
+}
+
+const props = defineProps<{
+ instanceList: ComposedInstance[];
+}>();
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ loading: false,
+});
+const instanceStore = useInstanceV1Store();
+
+const actions = computed((): Action[] => {
+ return [
+ {
+ icon: h(RefreshIcon),
+ text: t("common.sync"),
+ disabled: props.instanceList.length < 1 || state.loading,
+ click: syncSchema,
+ },
+ ];
+});
+
+const syncSchema = async () => {
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t("db.start-to-sync-schema"),
+ });
+ try {
+ state.loading = true;
+ await instanceStore.batchSyncInstance(
+ props.instanceList.map((instance) => instance.name)
+ );
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("db.successfully-synced-schema"),
+ });
+ } catch {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("db.failed-to-sync-schema"),
+ });
+ } finally {
+ state.loading = false;
+ }
+};
+</script>
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
index 8f17a50574..1091de6a49 100644
--- a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
@@ -1,44 +1,89 @@
<template>
- <BBGrid
- :column-list="columnList"
- :data-source="instanceList"
- class="mt-2 border-y"
- @click-row="clickInstance"
- >
- <template #item="{ item: instance }: InstanceRow">
- <div class="bb-grid-cell justify-center !px-2">
- <InstanceV1EngineIcon :instance="instance" />
- </div>
- <div class="bb-grid-cell">
- {{ instanceV1Name(instance) }}
- </div>
- <div class="bb-grid-cell">
- <EnvironmentV1Name
- :environment="instance.environmentEntity"
- :link="false"
- />
- </div>
- <div class="bb-grid-cell">
- {{ hostPortOfInstanceV1(instance) }}
- </div>
- <div class="bb-grid-cell hidden sm:flex">
- <button
- v-if="instance.externalLink?.trim().length != 0"
- class="btn-icon"
- @click.stop="window.open(urlfy(instance.externalLink), '_blank')"
- >
- <heroicons-outline:external-link class="w-4 h-4" />
- </button>
- </div>
- <div v-if="canAssignLicense" class="bb-grid-cell hover:underline">
- {{ instance.activation ? "Y" : "" }}
- </div>
- </template>
- </BBGrid>
+ <div>
+ <InstanceOperations
+ v-if="state.selectedInstance.size > 0"
+ class="mb-3"
+ :instance-list="selectedInstanceList"
+ @dismiss="state.selectedInstance.clear()"
+ />
+ <BBGrid
+ :column-list="columnList"
+ :data-source="instanceList"
+ :custom-header="true"
+ class="mt-2 border-y"
+ @click-row="clickInstance"
+ >
+ <template #header>
+ <div role="table-row" class="bb-grid-row bb-grid-header-row group">
+ <div
+ v-for="(column, index) in columnList"
+ :key="index"
+ role="table-cell"
+ class="bb-grid-header-cell capitalize"
+ :class="[column.class]"
+ >
+ <template v-if="index === 0 && allowSelection">
+ <input
+ type="checkbox"
+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
+ :checked="allSelectionState.checked"
+ :indeterminate="allSelectionState.indeterminate"
+ @input="
+ selectAllInstances(
+ ($event.target as HTMLInputElement).checked
+ )
+ "
+ />
+ </template>
+ <template v-else>{{ column.title }}</template>
+ </div>
+ </div>
+ </template>
+ <template #item="{ item: instance }: InstanceRow">
+ <div v-if="allowSelection" class="bb-grid-cell">
+ <input
+ type="checkbox"
+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
+ :checked="isInstanceSelected(instance)"
+ @click.stop="
+ toggleSelectInstance(instance, !isInstanceSelected(instance))
+ "
+ />
+ </div>
+ <div class="bb-grid-cell justify-center">
+ <InstanceV1EngineIcon :instance="instance" />
+ </div>
+ <div class="bb-grid-cell">
+ {{ instanceV1Name(instance) }}
+ </div>
+ <div class="bb-grid-cell">
+ <EnvironmentV1Name
+ :environment="instance.environmentEntity"
+ :link="false"
+ />
+ </div>
+ <div class="bb-grid-cell">
+ {{ hostPortOfInstanceV1(instance) }}
+ </div>
+ <div class="bb-grid-cell hidden sm:flex">
+ <button
+ v-if="instance.externalLink?.trim().length != 0"
+ class="btn-icon"
+ @click.stop="window.open(urlfy(instance.externalLink), '_blank')"
+ >
+ <heroicons-outline:external-link class="w-4 h-4" />
+ </button>
+ </div>
+ <div v-if="canAssignLicense" class="bb-grid-cell hover:underline">
+ {{ instance.activation ? "Y" : "" }}
+ </div>
+ </template>
+ </BBGrid>
+ </div>
</template>
<script lang="ts" setup>
-import { computed } from "vue";
+import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBGrid, BBGridColumn, BBGridRow } from "@/bbkit";
@@ -54,20 +99,36 @@ import InstanceV1EngineIcon from "../InstanceV1EngineIcon.vue";
export type InstanceRow = BBGridRow<ComposedInstance>;
+interface LocalState {
+ selectedInstance: Set<string>;
+ processing: boolean;
+}
+
const props = defineProps<{
instanceList: ComposedInstance[];
canAssignLicense: boolean;
+ allowSelection: boolean;
}>();
const { t } = useI18n();
-
const router = useRouter();
+const state = reactive<LocalState>({
+ selectedInstance: new Set(),
+ processing: false,
+});
const columnList = computed((): BBGridColumn[] => {
const list = [
+ // checkbox
{
title: "",
- width: "minmax(auto, 4rem)",
+ width: "minmax(auto, 3rem)",
+ hide: !props.allowSelection,
+ },
+ // engine icon
+ {
+ title: "",
+ width: "minmax(auto, 2rem)",
},
{
title: t("common.name"),
@@ -86,14 +147,13 @@ const columnList = computed((): BBGridColumn[] => {
width: { sm: "1fr" },
class: "hidden sm:flex",
},
- ];
- if (props.canAssignLicense) {
- list.push({
+ {
title: t("subscription.instance-assignment.license"),
width: "minmax(auto, 1fr)",
- });
- }
- return list;
+ hide: !props.canAssignLicense,
+ },
+ ];
+ return list.filter((col) => !col.hide);
});
const clickInstance = (
@@ -109,4 +169,47 @@ const clickInstance = (
router.push(url);
}
};
+
+const isInstanceSelected = (instance: ComposedInstance): boolean => {
+ return state.selectedInstance.has(instance.name);
+};
+
+const allSelectionState = computed(() => {
+ const checked = props.instanceList.every((instance) =>
+ state.selectedInstance.has(instance.name)
+ );
+ const indeterminate =
+ !checked &&
+ props.instanceList.some((instance) =>
+ state.selectedInstance.has(instance.name)
+ );
+
+ return {
+ checked,
+ indeterminate,
+ };
+});
+
+const toggleSelectInstance = (
+ instance: ComposedInstance,
+ selected: boolean
+) => {
+ if (selected) {
+ state.selectedInstance.add(instance.name);
+ } else {
+ state.selectedInstance.delete(instance.name);
+ }
+};
+
+const selectAllInstances = (selected: boolean): void => {
+ for (const instance of props.instanceList) {
+ toggleSelectInstance(instance, selected);
+ }
+};
+
+const selectedInstanceList = computed(() => {
+ return props.instanceList.filter((instance) =>
+ state.selectedInstance.has(instance.name)
+ );
+});
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 635e4c9280..2ca5db3f7a 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1066,6 +1066,7 @@
"select-database-user": "Select database user",
"new-database": "New Database",
"syncing": "Syncing ...",
+ "selected-n-instances": "{n} instance selected | {n} instances selected",
"create-migration-schema": "Create migration schema",
"missing-migration-schema": "Missing migration schema",
"unable-to-connect-instance-to-check-migration-schema": "Unable to connect instance to check migration schema",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3bd21170e2..583df66723 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1065,6 +1065,7 @@
"select-database-user": "Seleccionar usuario de base de datos",
"new-database": "Nueva base de datos",
"syncing": "Sincronizando...",
+ "selected-n-instances": "{n} instancia seleccionada | {n} instancias seleccionadas",
"create-migration-schema": "Crear esquema de migración",
"missing-migration-schema": "Falta el esquema de migración",
"unable-to-connect-instance-to-check-migration-schema": "No se pudo conectar la instancia para verificar el esquema de migración",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index f3c76f2668..c91b6afb2d 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1063,6 +1063,7 @@
"select-database-user": "选择数据库用户",
"new-database": "@:common.new@:common.database",
"syncing": "同步中 ...",
+ "selected-n-instances": "已选择 {n} 个实例",
"create-migration-schema": "@:common.create@:common.migration @:{'common.schema'}",
"missing-migration-schema": "缺少@:common.migration @:common.schema",
"unable-to-connect-instance-to-check-migration-schema": "无法连接到@:{'common.instance'}以检查@:{'common.migration'} @:{'common.schema'}",
diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.ts
index 2c898aadcd..eff308e9b2 100644
--- a/frontend/src/store/modules/v1/instance.ts
+++ b/frontend/src/store/modules/v1/instance.ts
@@ -103,6 +103,11 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
name: instance.name,
});
};
+ const batchSyncInstance = async (instanceNameList: string[]) => {
+ await instanceServiceClient.batchSyncInstance({
+ requests: instanceNameList.map((name) => ({ name })),
+ });
+ };
const fetchInstanceByName = async (name: string, silent = false) => {
const instance = await instanceServiceClient.getInstance(
{
@@ -216,6 +221,7 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
archiveInstance,
restoreInstance,
syncInstance,
+ batchSyncInstance,
fetchInstanceList,
fetchInstanceByName,
getInstanceByName,
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index 418c1d7cda..8a726754ce 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -58,7 +58,9 @@ export type FeatureType =
// Collaboration
| "bb.feature.shared-sql-script"
// Plugins
- | "bb.feature.plugin.openai";
+ | "bb.feature.plugin.openai"
+ // Instance count limit
+ | "bb.feature.instance-count";
export const instanceLimitFeature = new Set<FeatureType>([
// Change Workflow
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 90ed900282..b72b321093 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -24,6 +24,8 @@
/>
<InstanceV1Table
v-else-if="state.selectedIndex == INSTANCE_TAB"
+ :allow-selection="false"
+ :can-assign-license="false"
:instance-list="filteredInstanceList"
/>
<EnvironmentV1Table
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index c5c87609a8..1bb28e6fbf 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -1,11 +1,5 @@
<template>
<div class="flex flex-col relative">
- <DatabaseOperations
- v-if="selectedDatabases.length > 0"
- class="my-3"
- :databases="selectedDatabases"
- @dismiss="state.selectedDatabaseIds.clear()"
- />
<div class="px-4 py-2 flex justify-between items-center">
<EnvironmentTabFilter
:include-all="true"
@@ -55,6 +49,13 @@
</div>
</div>
+ <DatabaseOperations
+ v-if="selectedDatabases.length > 0"
+ class="mb-3"
+ :databases="selectedDatabases"
+ @dismiss="state.selectedDatabaseIds.clear()"
+ />
+
<DatabaseV1Table
pagination-class="mb-4"
:database-list="filteredDatabaseList"
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index f22c5acdaa..617faaa9f7 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -19,6 +19,7 @@
/>
</div>
<InstanceV1Table
+ :allow-selection="true"
:instance-list="filteredInstanceV1List"
:can-assign-license="subscriptionStore.currentPlan !== PlanType.FREE"
/>