Skip to content

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

Add MigrationHistoryDetailPage

天舟1c561c66dab9
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index 0cf88d211e..6fdcdb34bb 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -137,6 +137,7 @@ export default {
const databaseSlug = routeSlug.databaseSlug;
const tableName = routeSlug.tableName;
const dataSourceSlug = routeSlug.dataSourceSlug;
+ const migrationHistory = routeSlug.migrationHistorySlug;
const versionControlSlug = routeSlug.vcsSlug;
const list: Array<BreadcrumbItem> = [];
@@ -171,7 +172,7 @@ export default {
path: "/db",
});
- if (tableName || dataSourceSlug) {
+ if (tableName || dataSourceSlug || migrationHistory) {
const database = store.getters["database/databaseById"](
idFromSlug(databaseSlug)
);
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index b40f3940fa..5e44d6f533 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -64,6 +64,7 @@
</div>
<MigrationHistoryTable
v-if="state.migrationSetupStatus == 'OK'"
+ :databaseSectionList="[database]"
:historySectionList="migrationHistorySectionList"
/>
<BBAttention
diff --git a/frontend/src/components/MigrationHistoryTable.vue b/frontend/src/components/MigrationHistoryTable.vue
index adbddf6941..ca8ec80999 100644
--- a/frontend/src/components/MigrationHistoryTable.vue
+++ b/frontend/src/components/MigrationHistoryTable.vue
@@ -6,7 +6,7 @@
:showHeader="true"
:leftBordered="true"
:rightBordered="true"
- :rowClickable="false"
+ @click-row="clickHistory"
>
<template v-slot:header>
<template v-if="mode == 'DATABASE'">
@@ -72,9 +72,10 @@
<script lang="ts">
import { PropType } from "vue";
-import { MigrationHistory } from "../types";
-import { secondsToString } from "../utils";
+import { Database, MigrationHistory } from "../types";
+import { databaseSlug, migrationHistorySlug, secondsToString } from "../utils";
import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
+import { useRouter } from "vue-router";
type Mode = "DATABASE" | "PROJECT";
@@ -144,15 +145,31 @@ export default {
default: "DATABASE",
type: String as PropType<Mode>,
},
+ databaseSectionList: {
+ required: true,
+ type: Object as PropType<Database[]>,
+ },
historySectionList: {
required: true,
type: Object as PropType<BBTableSectionDataSource<MigrationHistory>[]>,
},
},
setup(props, ctx) {
+ const router = useRouter();
+
+ const clickHistory = function (section: number, row: number) {
+ const history = props.historySectionList[section].list[row];
+ router.push(
+ `/db/${databaseSlug(
+ props.databaseSectionList[section]
+ )}/history/${migrationHistorySlug(history)}`
+ );
+ };
+
return {
columnList: columnListMap.get(props.mode),
secondsToString,
+ clickHistory,
};
},
};
diff --git a/frontend/src/components/ProjectMigrationHistoryPanel.vue b/frontend/src/components/ProjectMigrationHistoryPanel.vue
index 59d8daec2c..7a14f3d5a2 100644
--- a/frontend/src/components/ProjectMigrationHistoryPanel.vue
+++ b/frontend/src/components/ProjectMigrationHistoryPanel.vue
@@ -7,6 +7,7 @@
<template v-if="state.migrationHistorySectionList.length > 0">
<MigrationHistoryTable
:mode="'PROJECT'"
+ :databaseSectionList="state.databaseSectionList"
:historySectionList="state.migrationHistorySectionList"
/>
</template>
@@ -56,6 +57,7 @@ import { fullDatabasePath } from "../utils";
const MAX_MIGRAION_HISTORY_COUNT = 5;
interface LocalState {
+ databaseSectionList: Database[];
migrationHistorySectionList: BBTableSectionDataSource<MigrationHistory>[];
}
@@ -79,10 +81,12 @@ export default {
const router = useRouter();
const state = reactive<LocalState>({
+ databaseSectionList: [],
migrationHistorySectionList: [],
});
const fetchMigrationHistory = (databaseList: Database[]) => {
+ state.databaseSectionList = [];
state.migrationHistorySectionList = [];
for (const database of databaseList) {
store
@@ -97,6 +101,8 @@ export default {
})
.then((migrationHistoryList: MigrationHistory[]) => {
if (migrationHistoryList.length > 0) {
+ state.databaseSectionList.push(database);
+
const title = `${database.name} (${database.instance.environment.name})`;
const index = state.migrationHistorySectionList.findIndex(
(item: BBTableSectionDataSource<MigrationHistory>) => {
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index c6cf1ed64b..4c6fb56d61 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -11,7 +11,7 @@ import DatabaseLayout from "../layouts/DatabaseLayout.vue";
import InstanceLayout from "../layouts/InstanceLayout.vue";
import SplashLayout from "../layouts/SplashLayout.vue";
import { store } from "../store";
-import { QuickActionType } from "../types";
+import { Database, QuickActionType } from "../types";
import { idFromSlug, isDBAOrOwner, isOwner } from "../utils";
// import PasswordReset from "../views/auth/PasswordReset.vue";
import Signin from "../views/auth/Signin.vue";
@@ -646,6 +646,24 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("../views/DataSourceDetail.vue"),
props: true,
},
+ {
+ path: "history/:migrationHistorySlug",
+ name: "workspace.database.history.detail",
+ meta: {
+ title: (route: RouteLocationNormalized) => {
+ const slug = route.params.migrationHistorySlug as string;
+ return (
+ "Migration - " +
+ store.getters["instance/migrationHistoryById"](
+ idFromSlug(slug)
+ ).version
+ );
+ },
+ allowBookmark: true,
+ },
+ component: () => import("../views/MigrationHistoryDetail.vue"),
+ props: true,
+ },
],
},
{
@@ -852,6 +870,7 @@ router.beforeEach((to, from, next) => {
const databaseSlug = routerSlug.databaseSlug;
const tableName = routerSlug.tableName;
const dataSourceSlug = routerSlug.dataSourceSlug;
+ const migrationHistorySlug = routerSlug.migrationHistorySlug;
const vcsSlug = routerSlug.vcsSlug;
if (principalId) {
@@ -955,8 +974,8 @@ router.beforeEach((to, from, next) => {
.dispatch("database/fetchDatabaseById", {
databaseId: idFromSlug(databaseSlug),
})
- .then((database) => {
- if (!tableName && !dataSourceSlug) {
+ .then((database: Database) => {
+ if (!tableName && !dataSourceSlug && !migrationHistorySlug) {
next();
} else if (tableName) {
store
@@ -990,6 +1009,22 @@ router.beforeEach((to, from, next) => {
});
throw error;
});
+ } else if (migrationHistorySlug) {
+ store
+ .dispatch("instance/fetchMigrationHistoryById", {
+ instanceId: database.instance.id,
+ migrationHistoryId: idFromSlug(migrationHistorySlug),
+ })
+ .then(() => {
+ next();
+ })
+ .catch((error) => {
+ next({
+ name: "error.404",
+ replace: false,
+ });
+ throw error;
+ });
}
})
.catch((error) => {
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 2f4189b539..c552accc67 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -11,6 +11,7 @@ import {
InstancePatch,
InstanceState,
MigrationHistory,
+ MigrationHistoryId,
ResourceIdentifier,
ResourceObject,
RowStatus,
@@ -73,6 +74,7 @@ function convertMigrationHistory(history: ResourceObject): MigrationHistory {
const state: () => InstanceState = () => ({
instanceById: new Map(),
instanceUserListById: new Map(),
+ migrationHistoryById: new Map(),
migrationHistoryListByIdAndDatabaseName: new Map(),
});
@@ -127,6 +129,12 @@ const getters = {
return state.instanceUserListById.get(instanceId) || [];
},
+ migrationHistoryById:
+ (state: InstanceState) =>
+ (migrationHistoryId: MigrationHistoryId): MigrationHistory | undefined => {
+ return state.migrationHistoryById.get(migrationHistoryId);
+ },
+
migrationHistoryListByInstanceIdAndDatabaseName:
(state: InstanceState) =>
(instanceId: InstanceId, databaseName: string): MigrationHistory[] => {
@@ -269,6 +277,30 @@ const actions = {
return rootGetters["sql/convert"](data);
},
+ async fetchMigrationHistoryById(
+ { commit, rootGetters }: any,
+ {
+ instanceId,
+ migrationHistoryId,
+ }: {
+ instanceId: InstanceId;
+ migrationHistoryId: MigrationHistoryId;
+ }
+ ) {
+ const data = (
+ await axios.get(
+ `/api/instance/${instanceId}/migration/history/${migrationHistoryId}`
+ )
+ ).data;
+ const migrationHistory = convertMigrationHistory(data.data);
+
+ commit("setMigrationHistoryById", {
+ migrationHistoryId,
+ migrationHistory,
+ });
+ return migrationHistory;
+ },
+
async fetchMigrationHistory(
{ commit }: any,
{
@@ -337,6 +369,19 @@ const mutations = {
state.instanceUserListById.set(instanceId, instanceUserList);
},
+ setMigrationHistoryById(
+ state: InstanceState,
+ {
+ migrationHistoryId,
+ migrationHistory,
+ }: {
+ migrationHistoryId: MigrationHistoryId;
+ migrationHistory: MigrationHistory;
+ }
+ ) {
+ state.migrationHistoryById.set(migrationHistoryId, migrationHistory);
+ },
+
setMigrationHistoryListByInstanceIdAndDatabaseName(
state: InstanceState,
{
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 95d70ea19d..b3f519760a 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -108,6 +108,20 @@ const getters = {
}
}
+ {
+ // /db/:databaseSlug/history/:migrationHistorySlug
+ // Total 3 elements, 2nd element is the database slug, 3rd element is the migration history slug
+ const migrationHistoryComponents = currentRoute.path.match(
+ "/db/([0-9a-zA-Z_-]+)/history/([0-9a-zA-Z_-]+)"
+ ) || ["/", undefined, undefined];
+ if (migrationHistoryComponents[1] && migrationHistoryComponents[2]) {
+ return {
+ databaseSlug: migrationHistoryComponents[1],
+ migrationHistorySlug: migrationHistoryComponents[2],
+ };
+ }
+ }
+
{
// /db/:databaseSlug
// Total 2 elements, 2nd element is the database slug
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 71843eff7e..bdf4d117e3 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -53,6 +53,7 @@ export type RouterSlug = {
databaseSlug?: string;
tableName?: string;
dataSourceSlug?: string;
+ migrationHistorySlug?: string;
vcsSlug?: string;
};
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index d027dc3dfd..c99c7ebdf2 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -1,3 +1,4 @@
+import { MigrationHistoryId } from ".";
import { Activity } from "./activity";
import { ServerInfo } from "./actuator";
import { Backup, BackupSetting } from "./backup";
@@ -99,6 +100,7 @@ export interface EnvironmentState {
export interface InstanceState {
instanceById: Map<InstanceId, Instance>;
instanceUserListById: Map<InstanceId, InstanceUser[]>;
+ migrationHistoryById: Map<MigrationHistoryId, MigrationHistory>;
// The key is a concatenation of instance id and database name
migrationHistoryListByIdAndDatabaseName: Map<string, MigrationHistory[]>;
}
diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.ts
index e8c90a9db4..36dd78eefa 100644
--- a/frontend/src/utils/slug.ts
+++ b/frontend/src/utils/slug.ts
@@ -5,6 +5,7 @@ import {
Environment,
Instance,
IssueId,
+ MigrationHistory,
Project,
ProjectWebhook,
Task,
@@ -63,6 +64,12 @@ export function dataSourceSlug(dataSource: DataSource): string {
return [slug(dataSource.name), dataSource.id].join("-");
}
+export function migrationHistorySlug(
+ migrationHistory: MigrationHistory
+): string {
+ return [slug(migrationHistory.version), migrationHistory.id].join("-");
+}
+
export function fullDatabasePath(database: Database): string {
return `/db/${databaseSlug(database)}`;
}
diff --git a/frontend/src/views/MigrationHistoryDetail.vue b/frontend/src/views/MigrationHistoryDetail.vue
new file mode 100644
index 0000000000..fd5df17caf
--- /dev/null
+++ b/frontend/src/views/MigrationHistoryDetail.vue
@@ -0,0 +1,193 @@
+<template>
+ <div class="flex-1 overflow-auto focus:outline-none" tabindex="0">
+ <main class="flex-1 relative pb-8 overflow-y-auto">
+ <!-- Highlight Panel -->
+ <div
+ class="
+ px-4
+ pb-4
+ border-b border-block-border
+ md:flex md:items-center md:justify-between
+ "
+ >
+ <div class="flex-1 min-w-0 space-y-3">
+ <!-- Summary -->
+ <div class="flex items-center">
+ <div class="flex items-center">
+ <h1 class="pt-2 text-xl font-bold leading-6 text-main truncate">
+ Version {{ migrationHistory.version }}
+ </h1>
+ </div>
+ </div>
+ <p class="text-control">
+ Type {{ migrationHistory.type }} -
+ {{ migrationHistory.description }}
+ </p>
+ <dl
+ class="
+ flex flex-col
+ space-y-1
+ md:space-y-0 md:flex-row md:flex-wrap
+ "
+ >
+ <dt class="sr-only">Issue</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel">Issue&nbsp;-&nbsp;</span>
+ <router-link
+ :to="`/issue/${migrationHistory.issueId}`"
+ class="normal-link"
+ >
+ {{ migrationHistory.issueId }} ({{ migrationHistory.engine }})
+ </router-link>
+ </dd>
+ <dt class="sr-only">Duration</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel">Duration&nbsp;-&nbsp;</span>
+ {{ secondsToString(migrationHistory.executionDuration) }}
+ </dd>
+ <dt class="sr-only">Creator</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel">Creator&nbsp;-&nbsp;</span>
+ {{ migrationHistory.creator }}
+ </dd>
+ <dt class="sr-only">Created</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel">Created&nbsp;-&nbsp;</span>
+ {{ humanizeTs(migrationHistory.createdTs) }}
+ </dd>
+ </dl>
+ </div>
+ </div>
+
+ <div class="mt-6 px-4">
+ <a
+ href="#statement"
+ id="statement"
+ class="flex items-center text-lg text-main mb-2 hover:underline"
+ >
+ Statement
+ <button
+ tabindex="-1"
+ class="btn-icon ml-1"
+ @click.prevent="copyStatement"
+ >
+ <svg
+ class="w-6 h-6"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
+ ></path>
+ </svg>
+ </button>
+ </a>
+ <div v-highlight class="border p-2 whitespace-pre-wrap">
+ {{ migrationHistory.statement }}
+ </div>
+ <a
+ href="#schema"
+ id="schema"
+ class="flex items-center text-lg text-main mt-6 mb-2 hover:underline"
+ >
+ Schema Snapshot
+ <button
+ tabindex="-1"
+ class="btn-icon ml-1"
+ @click.prevent="copySchema"
+ >
+ <svg
+ class="w-6 h-6"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
+ ></path>
+ </svg>
+ </button>
+ </a>
+ <div v-highlight class="border p-2 whitespace-pre-wrap">
+ {{ migrationHistory.schema }}
+ </div>
+ </div>
+ </main>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed } from "@vue/runtime-core";
+import { useStore } from "vuex";
+import { toClipboard } from "@soerenmartius/vue3-clipboard";
+import ColumnTable from "../components/ColumnTable.vue";
+import IndexTable from "../components/IndexTable.vue";
+import { idFromSlug, secondsToString } from "../utils";
+
+export default {
+ name: "MigrationHistoryDetail",
+ props: {
+ databaseSlug: {
+ required: true,
+ type: String,
+ },
+ migrationHistorySlug: {
+ required: true,
+ type: String,
+ },
+ },
+ components: { ColumnTable, IndexTable },
+ setup(props, ctx) {
+ const store = useStore();
+
+ const database = computed(() => {
+ return store.getters["database/databaseById"](
+ idFromSlug(props.databaseSlug)
+ );
+ });
+
+ const migrationHistory = computed(() => {
+ return store.getters["instance/migrationHistoryById"](
+ idFromSlug(props.migrationHistorySlug)
+ );
+ });
+
+ const copyStatement = () => {
+ toClipboard(migrationHistory.value.statement).then(() => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "INFO",
+ title: `Statement copied to clipboard.`,
+ });
+ });
+ };
+
+ const copySchema = () => {
+ toClipboard(migrationHistory.value.schema).then(() => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "INFO",
+ title: `Schema copied to clipboard.`,
+ });
+ });
+ };
+
+ return {
+ secondsToString,
+ database,
+ migrationHistory,
+ copyStatement,
+ copySchema,
+ };
+ },
+};
+</script>
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index eff2b18917..a037236e07 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -245,6 +245,8 @@ type MigrationHistory struct {
}
type MigrationHistoryFind struct {
+ ID *int
+
Database *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 9b1220247f..d1d88d03e4 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -599,6 +599,9 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
defer tx.Rollback()
where, args := []string{"1 = 1"}, []interface{}{}
+ if v := find.ID; v != nil {
+ where, args = append(where, "id = ?"), append(args, *v)
+ }
if v := find.Database; v != nil {
where, args = append(where, "namespace = ?"), append(args, *v)
}
diff --git a/server/acl_casbin_policy_dba.csv b/server/acl_casbin_policy_dba.csv
index a5b35305a4..a640f5307b 100644
--- a/server/acl_casbin_policy_dba.csv
+++ b/server/acl_casbin_policy_dba.csv
@@ -30,6 +30,7 @@ p, DBA, /instance/{id}/user, GET
p, DBA, /instance/{id}/migration, POST
p, DBA, /instance/{id}/migration/status, GET
p, DBA, /instance/{id}/migration/history, GET
+p, DBA, /instance/{id}/migration/history/{historyId}, GET
p, DBA, /database, POST
p, DBA, /database, GET
p, DBA, /database/{id}, GET
diff --git a/server/acl_casbin_policy_developer.csv b/server/acl_casbin_policy_developer.csv
index f6201d25d7..34c0a62233 100644
--- a/server/acl_casbin_policy_developer.csv
+++ b/server/acl_casbin_policy_developer.csv
@@ -25,6 +25,7 @@ p, DEVELOPER, /instance/{id}, GET
p, DEVELOPER, /instance/{id}/user, GET
p, DEVELOPER, /instance/{id}/migration/status, GET
p, DEVELOPER, /instance/{id}/migration/history, GET
+p, DEVELOPER, /instance/{id}/migration/history/{historyId}, GET
p, DEVELOPER, /instance/{id}, GET
p, DEVELOPER, /database, POST
p, DEVELOPER, /database, GET
diff --git a/server/acl_casbin_policy_owner.csv b/server/acl_casbin_policy_owner.csv
index 94c12b6508..20b113e8da 100644
--- a/server/acl_casbin_policy_owner.csv
+++ b/server/acl_casbin_policy_owner.csv
@@ -34,6 +34,7 @@ p, OWNER, /instance/{id}/user, GET
p, OWNER, /instance/{id}/migration, POST
p, OWNER, /instance/{id}/migration/status, GET
p, OWNER, /instance/{id}/migration/history, GET
+p, OWNER, /instance/{id}/migration/history/{historyId}, GET
p, OWNER, /database, POST
p, OWNER, /database, GET
p, OWNER, /database/{id}, GET
diff --git a/server/instance.go b/server/instance.go
index 160597fd23..1259d70433 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -274,6 +274,63 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
return nil
})
+ g.GET("/instance/:instanceId/migration/history/:historyId", func(c echo.Context) error {
+ id, err := strconv.Atoi(c.Param("instanceId"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Intance ID is not a number: %s", c.Param("instanceId"))).SetInternal(err)
+ }
+
+ historyId, err := strconv.Atoi(c.Param("historyId"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("History ID is not a number: %s", c.Param("historyId"))).SetInternal(err)
+ }
+
+ instance, err := s.ComposeInstanceById(context.Background(), id)
+ if err != nil {
+ if common.ErrorCode(err) == common.ENOTFOUND {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
+ }
+
+ find := &db.MigrationHistoryFind{ID: &historyId}
+ driver, err := GetDatabaseDriver(instance, "", s.l)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch migration history ID %d for instance %q", id, instance.Name)).SetInternal(err)
+ }
+ defer driver.Close(context.Background())
+ list, err := driver.FindMigrationHistoryList(context.Background(), find)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch migration history list").SetInternal(err)
+ }
+ if len(list) == 0 {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Migration history ID %d not found for instance %q", historyId, instance.Name))
+ }
+ entry := list[0]
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, &api.MigrationHistory{
+ ID: entry.ID,
+ Creator: entry.Creator,
+ CreatedTs: entry.CreatedTs,
+ Updater: entry.Updater,
+ UpdatedTs: entry.UpdatedTs,
+ Database: entry.Namespace,
+ Engine: entry.Engine,
+ Type: entry.Type,
+ Version: entry.Version,
+ Description: entry.Description,
+ Statement: entry.Statement,
+ Schema: entry.Schema,
+ ExecutionDuration: entry.ExecutionDuration,
+ IssueId: entry.IssueId,
+ Payload: entry.Payload,
+ }); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal migration history response for instance: %v", instance.Name)).SetInternal(err)
+ }
+ return nil
+ })
+
g.GET("/instance/:instanceId/migration/history", func(c echo.Context) error {
id, err := strconv.Atoi(c.Param("instanceId"))
if err != nil {
@@ -303,32 +360,33 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
historyList := []*api.MigrationHistory{}
driver, err := GetDatabaseDriver(instance, "", s.l)
- if err == nil {
- defer driver.Close(context.Background())
- list, err := driver.FindMigrationHistoryList(context.Background(), find)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch migration history list").SetInternal(err)
- }
-
- for _, entry := range list {
- historyList = append(historyList, &api.MigrationHistory{
- ID: entry.ID,
- Creator: entry.Creator,
- CreatedTs: entry.CreatedTs,
- Updater: entry.Updater,
- UpdatedTs: entry.UpdatedTs,
- Database: entry.Namespace,
- Engine: entry.Engine,
- Type: entry.Type,
- Version: entry.Version,
- Description: entry.Description,
- Statement: entry.Statement,
- Schema: entry.Schema,
- ExecutionDuration: entry.ExecutionDuration,
- IssueId: entry.IssueId,
- Payload: entry.Payload,
- })
- }
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch migration history for instance %q", instance.Name)).SetInternal(err)
+ }
+ defer driver.Close(context.Background())
+ list, err := driver.FindMigrationHistoryList(context.Background(), find)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch migration history list").SetInternal(err)
+ }
+
+ for _, entry := range list {
+ historyList = append(historyList, &api.MigrationHistory{
+ ID: entry.ID,
+ Creator: entry.Creator,
+ CreatedTs: entry.CreatedTs,
+ Updater: entry.Updater,
+ UpdatedTs: entry.UpdatedTs,
+ Database: entry.Namespace,
+ Engine: entry.Engine,
+ Type: entry.Type,
+ Version: entry.Version,
+ Description: entry.Description,
+ Statement: entry.Statement,
+ Schema: entry.Schema,
+ ExecutionDuration: entry.ExecutionDuration,
+ IssueId: entry.IssueId,
+ Payload: entry.Payload,
+ })
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)