Skip to content

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

Add schema version link to the backup table row

天舟4ef3c7f7c6c6
diff --git a/frontend/src/components/BackupTable.vue b/frontend/src/components/BackupTable.vue
index 0fe1b40225..2893c26abe 100644
--- a/frontend/src/components/BackupTable.vue
+++ b/frontend/src/components/BackupTable.vue
@@ -17,10 +17,11 @@
<BBTableHeaderCell class="w-48" :title="columnList[2].title" />
<BBTableHeaderCell class="w-16" :title="columnList[3].title" />
<BBTableHeaderCell class="w-16" :title="columnList[4].title" />
+ <BBTableHeaderCell class="w-16" :title="columnList[5].title" />
<BBTableHeaderCell
v-if="allowEdit"
class="w-4"
- :title="columnList[5].title"
+ :title="columnList[6].title"
/>
</template>
<template v-slot:body="{ rowData: backup }">
@@ -83,6 +84,11 @@
: backup.comment
}}
</BBTableCell>
+ <BBTableCell>
+ <div class="normal-link" @click.prevent="gotoMigrationHistory(backup)">
+ {{ backup.migrationHistoryVersion }}
+ </div>
+ </BBTableCell>
<BBTableCell>
{{ humanizeTs(backup.createdTs) }}
</BBTableCell>
@@ -132,10 +138,11 @@
<script lang="ts">
import { computed, PropType, reactive } from "vue";
import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
-import { Backup, Database } from "../types";
-import { bytesToString } from "../utils";
+import { Backup, Database, MigrationHistory } from "../types";
+import { bytesToString, databaseSlug, migrationHistorySlug } from "../utils";
import { useStore } from "vuex";
import CreateDatabasePrepForm from "../components/CreateDatabasePrepForm.vue";
+import { useRouter } from "vue-router";
const EDIT_COLUMN_LIST: BBTableColumn[] = [
{
@@ -147,6 +154,9 @@ const EDIT_COLUMN_LIST: BBTableColumn[] = [
{
title: "Comment",
},
+ {
+ title: "Schema version",
+ },
{
title: "Time",
},
@@ -168,6 +178,9 @@ const NON_EDIT_COLUMN_LIST: BBTableColumn[] = [
{
title: "Comment",
},
+ {
+ title: "Schema version",
+ },
{
title: "Time",
},
@@ -199,6 +212,7 @@ export default {
},
},
setup(props, ctx) {
+ const router = useRouter();
const store = useStore();
const state = reactive<LocalState>({
@@ -248,12 +262,32 @@ export default {
}
};
+ const gotoMigrationHistory = (backup: Backup) => {
+ store
+ .dispatch("instance/fetchMigrationHistoryByVersion", {
+ instanceId: props.database.instance.id,
+ databaseName: props.database.name,
+ version: backup.migrationHistoryVersion,
+ })
+ .then((history: MigrationHistory) => {
+ router.push({
+ name: "workspace.database.history.detail",
+ params: {
+ databaseSlug: databaseSlug(props.database),
+ migrationHistorySlug: migrationHistorySlug(history),
+ },
+ hash: "#schema",
+ });
+ });
+ };
+
const columnList = computed(() => {
return props.allowEdit ? EDIT_COLUMN_LIST : NON_EDIT_COLUMN_LIST;
});
return {
state,
+ gotoMigrationHistory,
columnList,
bytesToString,
backupSectionList,
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index c552accc67..c6c665313b 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -301,6 +301,39 @@ const actions = {
return migrationHistory;
},
+ async fetchMigrationHistoryByVersion(
+ { commit }: any,
+ {
+ instanceId,
+ databaseName,
+ version,
+ }: {
+ instanceId: InstanceId;
+ databaseName: string;
+ version: string;
+ }
+ ) {
+ const data = (
+ await axios.get(
+ `/api/instance/${instanceId}/migration/history?database=${databaseName}&version=${version}`
+ )
+ ).data.data;
+ const historyList = data.map((history: ResourceObject) => {
+ return convertMigrationHistory(history);
+ });
+
+ if (historyList.length > 0) {
+ commit("setMigrationHistoryById", {
+ migrationHistoryId: historyList[0].id,
+ migrationHistory: historyList[0],
+ });
+ return historyList[0];
+ }
+ throw new Error(
+ `Migration version ${version} not found in database ${databaseName}.`
+ );
+ },
+
async fetchMigrationHistory(
{ commit }: any,
{
diff --git a/frontend/src/types/backup.ts b/frontend/src/types/backup.ts
index d275436272..bb2f066ee1 100644
--- a/frontend/src/types/backup.ts
+++ b/frontend/src/types/backup.ts
@@ -24,6 +24,7 @@ export type Backup = {
status: BackupStatus;
type: BackupType;
storageBackend: BackupStorageBackend;
+ migrationHistoryVersion: string;
path: string;
comment: string;
};
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index a037236e07..e4af832a5a 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -248,6 +248,7 @@ type MigrationHistoryFind struct {
ID *int
Database *string
+ Version *string
// If specified, then it will only fetch "Limit" most recent migration histories
Limit *int
}
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index d1d88d03e4..91728ccc9c 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -605,6 +605,9 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if v := find.Database; v != nil {
where, args = append(where, "namespace = ?"), append(args, *v)
}
+ if v := find.Version; v != nil {
+ where, args = append(where, "version = ?"), append(args, *v)
+ }
var query = `
SELECT
diff --git a/server/instance.go b/server/instance.go
index 1259d70433..e26e77b62d 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -350,6 +350,10 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
if databaseStr != "" {
find.Database = &databaseStr
}
+ versionStr := c.QueryParams().Get("version")
+ if versionStr != "" {
+ find.Version = &versionStr
+ }
if limitStr := c.QueryParam("limit"); limitStr != "" {
limit, err := strconv.Atoi(limitStr)
if err != nil {