Skip to content

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

chore: instance sync (#13905)

ecmadao93c51a7e8335
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 069e069ce9..48914c0c22 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1415,6 +1415,12 @@
"select-database-user": "Select database user",
"new-database": "New Database",
"syncing": "Syncing ...",
+ "sync": {
+ "self": "Sync instance",
+ "sync-all": "Sync all databases",
+ "sync-new": "Only sync new databases",
+ "sync-all-tip": "Database sync is asynchronous and might take a few seconds to minutes"
+ },
"selected-n-instances": "{n} instance selected | {n} instances selected",
"create-migration-schema": "Create migration schema",
"missing-migration-schema": "Missing migration schema",
@@ -3473,7 +3479,7 @@
"apply-to-all-projects": "Apply to all projects"
},
"custom-roles": {
- "self":"Custom roles"
+ "self": "Custom roles"
},
"workspace-admin": {
"self": "Workspace Admin",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index ef3347e7e4..9218f21c73 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1415,6 +1415,12 @@
"select-database-user": "Seleccionar usuario de base de datos",
"new-database": "Nueva base de datos",
"syncing": "Sincronizando...",
+ "sync": {
+ "self": "Instancia de sincronización",
+ "sync-all": "Sincronizar todas las bases de datos",
+ "sync-new": "Sincronizar únicamente bases de datos nuevas",
+ "sync-all-tip": "La sincronización de la base de datos es asincrónica y puede tardar entre unos segundos y minutos."
+ },
"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",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index fa29a8c641..4ea857ca3d 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1415,6 +1415,12 @@
"select-database-user": "データベースユーザーの選択",
"new-database": "@:common.new@:common.database",
"syncing": "同期中 ...",
+ "sync": {
+ "self": "同期インスタンス",
+ "sync-all": "すべてのデータベースを同期する",
+ "sync-new": "新しいデータベースのみを同期する",
+ "sync-all-tip": "データベースの同期は非同期で、数秒から数分かかる場合があります。"
+ },
"selected-n-instances": "{n} 個のインスタンスが選択されました",
"create-migration-schema": "@:common.create@:common.migration @:{'common.schema'}",
"missing-migration-schema": "@:common.migration @:common.schema がありません",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 587dee294d..e902b1613f 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1415,6 +1415,12 @@
"select-database-user": "选择数据库用户",
"new-database": "@:common.new@:common.database",
"syncing": "同步中 ...",
+ "sync": {
+ "self": "同步实例",
+ "sync-all": "同步所有数据库",
+ "sync-new": "仅同步新数据库",
+ "sync-all-tip": "数据库同步是异步的,可能需要几秒到几分钟"
+ },
"selected-n-instances": "已选择 {n} 个实例",
"create-migration-schema": "@:common.create@:common.migration @:{'common.schema'}",
"missing-migration-schema": "缺少@:common.migration @:common.schema",
@@ -1698,7 +1704,7 @@
"auto-info": "如果预检查都通过的话,会自动发布,执行变更。",
"manual-by-last-approver": "自定义审批的最后一个审批人发布",
"manual-by-dedicated-roles": "特定角色手工发布",
- "manual-by-dedicated-roles-info": "允许以下任一选中角色,点击「发布」按钮后,执行变更。",
+ "manual-by-dedicated-roles-info": "允许以下任一选中角色,点击「发布」按钮后,执行变更。"
},
"environment-tier": {
"name": "环境级别",
diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.ts
index c0569ab42a..ab954189e6 100644
--- a/frontend/src/store/modules/v1/instance.ts
+++ b/frontend/src/store/modules/v1/instance.ts
@@ -79,9 +79,10 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
const composed = await upsertInstances([instance]);
return composed[0];
};
- const syncInstance = async (instance: Instance) => {
+ const syncInstance = async (instance: Instance, enableFullSync: boolean) => {
await instanceServiceClient.syncInstance({
name: instance.name,
+ enableFullSync,
});
};
const batchSyncInstances = async (instanceNameList: string[]) => {
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 170f006443..e03fc0fa4d 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -12,18 +12,26 @@
<NTabs>
<template #suffix>
<div class="space-x-2">
- <NButton
+ <NDropdown
v-if="allowSyncInstance"
- :loading="state.syncingSchema"
- @click.prevent="syncSchema"
+ :trigger="'click'"
+ :options="syncInstnceOptions"
+ :render-label="renderDropdownLabel"
+ :disabled="state.syncingSchema"
+ @select="syncSchema"
>
- <template v-if="state.syncingSchema">
- {{ $t("instance.syncing") }}
- </template>
- <template v-else>
- {{ $t("common.sync-now") }}
- </template>
- </NButton>
+ <NButton icon-placement="right" :loading="state.syncingSchema">
+ <template #icon>
+ <ChevronDownIcon class="w-4" />
+ </template>
+ <template v-if="state.syncingSchema">
+ {{ $t("instance.syncing") }}
+ </template>
+ <template v-else>
+ {{ $t("instance.sync.self") }}
+ </template>
+ </NButton>
+ </NDropdown>
<NButton
v-if="allowCreateDatabase"
type="primary"
@@ -71,9 +79,11 @@
</Drawer>
</template>
-<script lang="ts" setup>
+<script lang="tsx" setup>
import { useTitle } from "@vueuse/core";
-import { NButton, NTabPane, NTabs } from "naive-ui";
+import { ChevronDownIcon } from "lucide-vue-next";
+import type { DropdownOption } from "naive-ui";
+import { NButton, NTabPane, NTabs, NDropdown, NTooltip } from "naive-ui";
import type { ClientError } from "nice-grpc-web";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
@@ -148,12 +158,46 @@ const instance = computed(() => {
`${instanceNamePrefix}${props.instanceId}`
);
});
+
const environment = computed(() => {
return useEnvironmentV1Store().getEnvironmentByName(
instance.value.environment
);
});
+type syncInstanceKey = "sync-all" | "sync-new";
+
+const renderDropdownLabel = (option: DropdownOption) => {
+ if (option.key === "sync-new") {
+ return <span>{option.label}</span>;
+ }
+ return (
+ <NTooltip placement="top-start">
+ {{
+ trigger: () => option.label,
+ default: () => (
+ <span class="text-sm text-nowrap">
+ {t("instance.sync.sync-all-tip")}
+ </span>
+ ),
+ }}
+ </NTooltip>
+ );
+};
+
+const syncInstnceOptions = computed((): DropdownOption[] => {
+ return [
+ {
+ key: "sync-all",
+ label: t("instance.sync.sync-all"),
+ },
+ {
+ key: "sync-new",
+ label: t("instance.sync.sync-new"),
+ },
+ ];
+});
+
const { databaseList, listCache, ready } = useDatabaseV1List(
instance.value.name
);
@@ -178,10 +222,20 @@ const allowCreateDatabase = computed(() => {
);
});
-const syncSchema = async () => {
+const syncSchema = async (key: syncInstanceKey) => {
state.syncingSchema = true;
try {
- await instanceV1Store.syncInstance(instance.value);
+ await instanceV1Store.syncInstance(
+ instance.value,
+ key === "sync-all" /* enable full sync */
+ );
+ if (key === "sync-all") {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("instance.sync.sync-all-tip"),
+ });
+ }
// Remove the database list cache for the instance.
listCache.cacheMap.delete(listCache.getCacheKey(instance.value.name));
await wrapRefAsPromise(ready, true);