Skip to content

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

feat: display SDL issue's change detail (#4853)

Liu Ji924c3ac5a8a4
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index b627c4555f..ea892a4803 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -71,6 +71,9 @@
@run-checks="runTaskChecks"
/>
</div>
+ <section v-if="showIssueTaskSDLPanel" class="mb-4">
+ <IssueTaskSDLPanel />
+ </section>
<section v-if="showIssueTaskStatementPanel" class="border-b mb-4">
<IssueTaskStatementPanel :sql-hint="sqlHint()" />
</section>
@@ -109,6 +112,7 @@ import IssueStagePanel from "./IssueStagePanel.vue";
import IssueStatusTransitionButtonGroup from "./IssueStatusTransitionButtonGroup.vue";
import IssueOutputPanel from "./IssueOutputPanel.vue";
import IssueSidebar from "./IssueSidebar.vue";
+import IssueTaskSDLPanel from "./IssueTaskSDLPanel.vue";
import IssueTaskStatementPanel from "./IssueTaskStatementPanel.vue";
import IssueDescriptionPanel from "./IssueDescriptionPanel.vue";
import IssueActivityPanel from "./IssueActivityPanel.vue";
@@ -248,7 +252,17 @@ const showIssueOutputPanel = computed(() => {
return !props.create && issueTemplate.value.outputFieldList.length > 0;
});
+const showIssueTaskSDLPanel = computed(() => {
+ if (create.value) return false;
+ const task = selectedTask.value as Task;
+ return (
+ task.type === "bb.task.database.schema.update-sdl" && task.status === "DONE"
+ );
+});
+
const showIssueTaskStatementPanel = computed(() => {
+ if (showIssueTaskSDLPanel.value) return false;
+
const task = selectedTask.value;
if (task.type === "bb.task.database.schema.baseline" && !create.value) {
return false;
diff --git a/frontend/src/components/Issue/IssueTaskSDLPanel.vue b/frontend/src/components/Issue/IssueTaskSDLPanel.vue
new file mode 100644
index 0000000000..9470f6a325
--- /dev/null
+++ b/frontend/src/components/Issue/IssueTaskSDLPanel.vue
@@ -0,0 +1,159 @@
+<template>
+ <div
+ class="flex flex-col md:flex-row md:justify-between md:items-center gap-2 md:gap-4"
+ >
+ <div class="flex space-x-4 flex-1">
+ <div class="py-2 text-sm font-medium text-control">
+ {{ $t("common.sql") }}
+ <button
+ v-if="!hasFeature('bb.feature.sql-review')"
+ type="button"
+ class="ml-1 btn-small py-0.5 inline-flex items-center text-accent"
+ @click.prevent="state.showFeatureModal = true"
+ >
+ 🎈{{ $t("sql-review.unlock-full-feature") }}
+ </button>
+ </div>
+ </div>
+ </div>
+ <div class="w-full">
+ <div
+ v-if="changeHistory.loading"
+ class="h-20 flex flex-col items-center justify-center"
+ >
+ <BBSpin />
+ </div>
+ <template v-else>
+ <NTabs
+ v-if="changeHistory.history"
+ v-model:value="state.tab"
+ pane-style="padding-top: 0.25rem"
+ >
+ <NTabPane name="diff" :tab="$t('issue.sdl.schema-change')">
+ <CodeDiff
+ :old-string="changeHistory.history.schemaPrev"
+ :new-string="changeHistory.history.schema"
+ output-format="side-by-side"
+ data-label="bb-change-history-code-diff-block"
+ /></NTabPane>
+ <NTabPane
+ name="statement"
+ :tab="$t('issue.sdl.generated-ddl-statements')"
+ >
+ <HighlightCodeBlock
+ class="border px-2 whitespace-pre-wrap"
+ :code="changeHistory.history.statement"
+ />
+ </NTabPane>
+ <NTabPane name="schema" :tab="$t('issue.sdl.full-schema')">
+ <HighlightCodeBlock
+ class="border px-2 whitespace-pre-wrap"
+ :code="changeHistory.history.schema"
+ />
+ </NTabPane>
+ </NTabs>
+ </template>
+ </div>
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.sql-review"
+ @cancel="state.showFeatureModal = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { NTabs, NTabPane } from "naive-ui";
+import { reactive, watch, computed } from "vue";
+import { CodeDiff } from "v-code-diff";
+
+import { hasFeature, useInstanceStore } from "@/store";
+import { useIssueLogic } from "./logic";
+import { MigrationHistory, Task, TaskId } from "@/types";
+import HighlightCodeBlock from "../HighlightCodeBlock";
+
+type TabView = "diff" | "statement" | "schema";
+
+interface LocalState {
+ showFeatureModal: boolean;
+ tab: TabView;
+}
+
+const { selectedTask } = useIssueLogic();
+
+const state = reactive<LocalState>({
+ showFeatureModal: false,
+ tab: "diff",
+});
+
+const useChangeHistory = () => {
+ type ChangeHistoryState = {
+ task: Task;
+ loading: boolean;
+ history: MigrationHistory | undefined;
+ };
+ const emptyState = (task: Task): ChangeHistoryState => {
+ return {
+ task,
+ loading: true,
+ history: undefined,
+ };
+ };
+
+ const map = reactive(new Map<TaskId, ChangeHistoryState>());
+
+ const findLatestMigrationId = (task: Task) => {
+ if (task.status !== "DONE") return undefined;
+ const list = task.taskRunList;
+ for (let i = list.length - 1; i >= 0; i--) {
+ const taskRun = list[i];
+ if (taskRun.status === "DONE") {
+ return taskRun.result.migrationId;
+ }
+ }
+ return undefined;
+ };
+
+ const migrationId = computed(() => {
+ const task = selectedTask.value as Task;
+ return findLatestMigrationId(task);
+ });
+
+ watch(
+ [() => (selectedTask.value as Task).id, migrationId],
+ ([taskId, migrationId]) => {
+ const task = selectedTask.value as Task;
+ if (!map.has(taskId)) {
+ map.set(taskId, emptyState(task));
+ }
+ const finish = (ch?: MigrationHistory) => {
+ const state = map.get(taskId)!;
+ state.loading = false;
+ state.history = ch;
+ };
+
+ if (!migrationId) return finish();
+ useInstanceStore()
+ .fetchMigrationHistoryById({
+ instanceId: task.instance.id,
+ migrationHistoryId: migrationId,
+ })
+ .then((history) => {
+ // The latestMigrationId might change during fetching the
+ // migrationHistory.
+ // Should give up the result.
+ const latestMigrationId = findLatestMigrationId(task);
+ if (history.id !== latestMigrationId) return;
+ finish(history);
+ });
+ },
+ { immediate: true }
+ );
+
+ return computed(() => {
+ const task = selectedTask.value as Task;
+ return map.get(task.id) ?? emptyState(task);
+ });
+};
+
+const changeHistory = useChangeHistory();
+</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index eae602953a..6d3da14cce 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -646,6 +646,11 @@
"send-attention-request-successfully": "Request assignee {principal} attention successfully",
"needs-attention": "Attention needed",
"click-to-mark": "Click to request assignee attention"
+ },
+ "sdl": {
+ "schema-change": "Schema change",
+ "generated-ddl-statements": "Generated DDL statements",
+ "full-schema": "Full schema"
}
},
"alter-schema": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 7e7d1c3d25..cfae287041 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -644,6 +644,11 @@
"send-attention-request-successfully": "审核人 {principal} 已收到关注请求",
"needs-attention": "需要关注",
"click-to-mark": "点击以请求审核人关注"
+ },
+ "sdl": {
+ "schema-change": "Schema 变化",
+ "generated-ddl-statements": "生成的 DDL 语句",
+ "full-schema": "完整 schema"
}
},
"alter-schema": {