Skip to content

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

feat: update plan for sync schema (#3103)

boojacke1c9f5651d8b
diff --git a/frontend/src/bbkit/BBSelect.vue b/frontend/src/bbkit/BBSelect.vue
index 2517b59452..0813f98171 100644
--- a/frontend/src/bbkit/BBSelect.vue
+++ b/frontend/src/bbkit/BBSelect.vue
@@ -93,6 +93,9 @@
<heroicons-solid:check class="h-5 w-5" />
</span>
</li>
+ <div @click="close()">
+ <slot name="suffixItem"></slot>
+ </div>
</ul>
</div>
</transition>
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 72a0a82867..7b658cd1c9 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -252,7 +252,6 @@ import { useRoute, useRouter } from "vue-router";
import { ProjectId, QuickActionType } from "../types";
import { idFromSlug } from "../utils";
import {
- hasFeature,
useCommandStore,
useInstanceStore,
useSubscriptionStore,
@@ -357,12 +356,6 @@ export default defineComponent({
};
const syncDatabaseSchema = () => {
- if (!hasFeature("bb.feature.sync-schema")) {
- state.featureName = "bb.feature.sync-schema";
- state.showFeatureModal = true;
- return;
- }
-
state.modalTitle = t("database.sync-schema.title");
state.quickActionType = "quickaction.bb.database.schema.sync";
state.showModal = true;
diff --git a/frontend/src/components/SyncDatabaseSchemaPrepForm.vue b/frontend/src/components/SyncDatabaseSchemaPrepForm.vue
index f62c1880b4..ff8dcd3f6e 100644
--- a/frontend/src/components/SyncDatabaseSchemaPrepForm.vue
+++ b/frontend/src/components/SyncDatabaseSchemaPrepForm.vue
@@ -69,17 +69,25 @@
class=""
:selected-item="state.baseSchemaInfo.migrationHistory"
:item-list="
- databaseMigrationHistoryList(state.baseSchemaInfo.databaseId as DatabaseId)
- "
+ databaseMigrationHistoryList(state.baseSchemaInfo.databaseId as DatabaseId)
+ "
:placeholder="$t('migration-history.select')"
:show-prefix-item="true"
- @select-item="(migrationHistory: MigrationHistory) => state.baseSchemaInfo.migrationHistory = migrationHistory"
+ @select-item="(migrationHistory: MigrationHistory) => handleSchemaVersionSelect(migrationHistory)"
>
<template #menuItem="{ item: migrationHistory }">
<div class="flex items-center">
{{ migrationHistory.version }}
</div>
</template>
+ <template #suffixItem>
+ <div
+ class="w-full pl-3 leading-8 text-gray-600 cursor-pointer hover:text-accent"
+ @click="() => (state.showFeatureModal = true)"
+ >
+ {{ $t("database.sync-schema.more-version") }}
+ </div>
+ </template>
</BBSelect>
</div>
</div>
@@ -239,11 +247,18 @@
</div>
</div>
</div>
+
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.sync-schema"
+ @cancel="state.showFeatureModal = false"
+ />
</template>
<script lang="ts" setup>
import axios from "axios";
import dayjs from "dayjs";
+import { head } from "lodash-es";
import { computed, reactive, ref, watch } from "vue";
import { useEventListener } from "@vueuse/core";
import { useRouter } from "vue-router";
@@ -262,6 +277,7 @@ import {
MigrationContext,
} from "@/types";
import {
+ hasFeature,
pushNotification,
useDatabaseStore,
useInstanceStore,
@@ -289,6 +305,7 @@ type LocalState = {
engineType?: EngineType;
recommandStatement: string;
editStatement: string;
+ showFeatureModal: boolean;
};
const props = withDefaults(
@@ -320,6 +337,11 @@ const state = reactive<LocalState>({
targetSchemaInfo: {},
recommandStatement: "",
editStatement: "",
+ showFeatureModal: false,
+});
+
+const hasSyncSchemaFeature = computed(() => {
+ return hasFeature("bb.feature.sync-schema");
});
const allowSelectProject = computed(() => {
@@ -369,6 +391,9 @@ const databaseMigrationHistoryList = (databaseId: DatabaseId) => {
database.name
);
+ if (!hasSyncSchemaFeature.value) {
+ return [head(list)];
+ }
return list;
};
@@ -383,6 +408,15 @@ const gotoTargetDatabaseMigrationHistoryDetailPageWithId = (
router.push(url);
};
+const handleSchemaVersionSelect = (migrationHistory: MigrationHistory) => {
+ if (!hasSyncSchemaFeature.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ state.baseSchemaInfo.migrationHistory = migrationHistory;
+};
+
const handleCancelButtonClick = () => {
emit("dismiss");
};
@@ -505,10 +539,13 @@ watch(
if (isValidId(databaseId)) {
const database = databaseStore.getDatabaseById(databaseId as DatabaseId);
if (database) {
- await instanceStore.fetchMigrationHistory({
+ const migrationHistoryList = await instanceStore.fetchMigrationHistory({
instanceId: database.instance.id,
databaseName: database.name,
});
+ // Default select the first migration history.
+ state.baseSchemaInfo.migrationHistory = head(migrationHistoryList);
+ return;
}
}
state.baseSchemaInfo.migrationHistory = undefined;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index aa2f13b54b..96d15a27d3 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -910,7 +910,8 @@
"schema-diff": "Schema diff",
"synchronize-statements": "The generated DDL statements",
"select-schema-and-target-database-tip": "Please select the schema and database firstly.",
- "no-difference-tip": "There is no difference between the selected schema and target database schema."
+ "no-difference-tip": "There is no difference between the selected schema and target database schema.",
+ "more-version": "more..."
}
},
"repository": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 4c6a227d39..d4efdf090e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -910,7 +910,8 @@
"schema-diff": "Schema 比较结果",
"synchronize-statements": "生成的 Schema DDL 语句",
"select-schema-and-target-database-tip": "请先选择 Schema 和目标数据库",
- "no-difference-tip": "选定的 Schema 与目标数据库 Schema 之间没有区别。"
+ "no-difference-tip": "选定的 Schema 与目标数据库 Schema 之间没有区别。",
+ "more-version": "更多..."
}
},
"repository": {
diff --git a/server/openapi.go b/server/openapi.go
index 5f3f1f1c1b..e2ba1d1007 100644
--- a/server/openapi.go
+++ b/server/openapi.go
@@ -41,7 +41,7 @@ func (c *catalogService) GetFinder() *catalog.Finder {
func (s *Server) registerOpenAPIRoutes(g *echo.Group) {
g.POST("/sql/advise", s.sqlCheckController)
- g.POST("/sql/schema/diff", s.schemaDiff)
+ g.POST("/sql/schema/diff", schemaDiff)
}
type sqlCheckRequestBody struct {
@@ -208,11 +208,7 @@ type schemaDiffRequestBody struct {
// @Failure 400 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /sql/schema/diff [post].
-func (s *Server) schemaDiff(c echo.Context) error {
- if !s.feature(api.FeatureSyncSchema) {
- return echo.NewHTTPError(http.StatusForbidden, api.FeatureSyncSchema.AccessErrorMessage())
- }
-
+func schemaDiff(c echo.Context) error {
request := &schemaDiffRequestBody{}
body, err := io.ReadAll(c.Request().Body)
if err != nil {