Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add ProjectMigrationHistoryPanel and also make MigrationHistoryTable to support the Project mode
天舟77ba8b040e64
diff --git a/frontend/src/components/MigrationHistoryTable.vue b/frontend/src/components/MigrationHistoryTable.vueindex d5f8619ee2..adbddf6941 100644--- a/frontend/src/components/MigrationHistoryTable.vue+++ b/frontend/src/components/MigrationHistoryTable.vue@@ -1,32 +1,47 @@<template><BBTable- :columnList="COLUMN_LIST"+ :columnList="columnList":sectionDataSource="historySectionList"- :compactSection="true"+ :compactSection="mode == 'DATABASE'":showHeader="true":leftBordered="true":rightBordered="true":rowClickable="false"><template v-slot:header>- <BBTableHeaderCell- :leftPadding="4"- class="w-8"- :title="COLUMN_LIST[0].title"- />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[1].title" />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[2].title" />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[3].title" />- <BBTableHeaderCell class="w-32" :title="COLUMN_LIST[4].title" />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[5].title" />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[6].title" />- <BBTableHeaderCell class="w-16" :title="COLUMN_LIST[7].title" />+ <template v-if="mode == 'DATABASE'">+ <BBTableHeaderCell+ :leftPadding="4"+ class="w-8"+ :title="columnList[0].title"+ />+ <BBTableHeaderCell class="w-16" :title="columnList[1].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[2].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[3].title" />+ <BBTableHeaderCell class="w-32" :title="columnList[4].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[5].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[6].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[7].title" />+ </template>+ <template v-else>+ <BBTableHeaderCell+ :leftPadding="4"+ class="w-16"+ :title="columnList[0].title"+ />+ <BBTableHeaderCell class="w-16" :title="columnList[1].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[2].title" />+ <BBTableHeaderCell class="w-32" :title="columnList[3].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[4].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[5].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[6].title" />+ </template></template><template v-slot:body="{ rowData: history }">- <BBTableCell :leftPadding="4">+ <BBTableCell v-if="mode == 'DATABASE'" :leftPadding="4">{{ history.engine }}</BBTableCell>- <BBTableCell>+ <BBTableCell :leftPadding="mode == 'DATABASE' ? 0 : 4">{{ history.version }}</BBTableCell><BBTableCell>@@ -59,39 +74,76 @@import { PropType } from "vue";import { MigrationHistory } from "../types";import { secondsToString } from "../utils";-import { BBTableSectionDataSource } from "../bbkit/types";+import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";-const COLUMN_LIST = [- {- title: "Workflow",- },- {- title: "Version",- },- {- title: "Type",- },- {- title: "Issue",- },- {- title: "Description",- },- {- title: "Duration",- },- {- title: "Created",- },- {- title: "Creator",- },-];+type Mode = "DATABASE" | "PROJECT";++const columnListMap: Map<Mode, BBTableColumn[]> = new Map([+ [+ "DATABASE",+ [+ {+ title: "Workflow",+ },+ {+ title: "Version",+ },+ {+ title: "Type",+ },+ {+ title: "Issue",+ },+ {+ title: "Description",+ },+ {+ title: "Duration",+ },+ {+ title: "Created",+ },+ {+ title: "Creator",+ },+ ],+ ],+ [+ "PROJECT",+ [+ {+ title: "Version",+ },+ {+ title: "Type",+ },+ {+ title: "Issue",+ },+ {+ title: "Description",+ },+ {+ title: "Duration",+ },+ {+ title: "Created",+ },+ {+ title: "Creator",+ },+ ],+ ],+]);export default {name: "MigrationHistoryTable",components: {},props: {+ mode: {+ default: "DATABASE",+ type: String as PropType<Mode>,+ },historySectionList: {required: true,type: Object as PropType<BBTableSectionDataSource<MigrationHistory>[]>,@@ -99,7 +151,7 @@ export default {},setup(props, ctx) {return {- COLUMN_LIST,+ columnList: columnListMap.get(props.mode),secondsToString,};},diff --git a/frontend/src/components/ProjectMigrationHistoryPanel.vue b/frontend/src/components/ProjectMigrationHistoryPanel.vuenew file mode 100644index 0000000000..1b23121f35--- /dev/null+++ b/frontend/src/components/ProjectMigrationHistoryPanel.vue@@ -0,0 +1,107 @@+<template>+ <div class="flex flex-col space-y-2">+ <div class="textinfolabel">+ For database having migration history, we list up to 5 most recent+ histories below. You can click the database name to view all histories.+ </div>+ <MigrationHistoryTable+ :mode="'PROJECT'"+ :historySectionList="state.migrationHistorySectionList"+ />+ </div>+</template>++<script lang="ts">+import { PropType, reactive, ref, watchEffect } from "@vue/runtime-core";+import { useStore } from "vuex";+import MigrationHistoryTable from "../components/MigrationHistoryTable.vue";+import {+ Database,+ InstanceMigration,+ MigrationHistory,+ Project,+} from "../types";+import { useRouter } from "vue-router";+import { BBTableSectionDataSource } from "../bbkit/types";+import { fullDatabasePath } from "../utils";++// Show at most 5 recent migration history for each database+const MAX_MIGRAION_HISTORY_COUNT = 5;++interface LocalState {+ migrationHistorySectionList: BBTableSectionDataSource<MigrationHistory>[];+}++export default {+ name: "ProjectMigrationHistoryPanel",+ components: { MigrationHistoryTable },+ props: {+ project: {+ required: true,+ type: Object as PropType<Project>,+ },+ databaseList: {+ required: true,+ type: Object as PropType<Database[]>,+ },+ },+ setup(props, ctx) {+ const searchField = ref();++ const store = useStore();+ const router = useRouter();++ const state = reactive<LocalState>({+ migrationHistorySectionList: [],+ });++ const fetchMigrationHistory = (databaseList: Database[]) => {+ state.migrationHistorySectionList = [];+ for (const database of databaseList) {+ store+ .dispatch("instance/checkMigrationSetup", database.instance.id)+ .then((migration: InstanceMigration) => {+ if (migration.status == "OK") {+ store+ .dispatch("instance/fetchMigrationHistory", {+ instanceId: database.instance.id,+ databaseName: database.name,+ limit: MAX_MIGRAION_HISTORY_COUNT,+ })+ .then((migrationHistoryList: MigrationHistory[]) => {+ if (migrationHistoryList.length > 0) {+ const title = `${database.name} (${database.instance.environment.name})`;+ const index = state.migrationHistorySectionList.findIndex(+ (item: BBTableSectionDataSource<MigrationHistory>) => {+ return item.title == title;+ }+ );+ const newItem = {+ title: title,+ link: fullDatabasePath(database),+ list: migrationHistoryList,+ };+ if (index >= 0) {+ state.migrationHistorySectionList[index] = newItem;+ } else {+ state.migrationHistorySectionList.push(newItem);+ }+ }+ });+ }+ });+ }+ };++ const prepareMigrationHistoryList = () => {+ fetchMigrationHistory(props.databaseList);+ };+ watchEffect(prepareMigrationHistoryList);++ return {+ searchField,+ state,+ };+ },+};+</script>diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vueindex 3314bf813f..a6cc4cae37 100644--- a/frontend/src/components/ProjectOverviewPanel.vue+++ b/frontend/src/components/ProjectOverviewPanel.vue@@ -30,13 +30,11 @@</template><script lang="ts">-import { computed, reactive, watchEffect, PropType } from "vue";+import { reactive, watchEffect, PropType } from "vue";import { useStore } from "vuex";-import { useRouter } from "vue-router";import DatabaseTable from "../components/DatabaseTable.vue";import IssueTable from "../components/IssueTable.vue";-import { Issue, Project } from "../types";-import { sortDatabaseList } from "../utils";+import { Database, Issue, Project } from "../types";interface LocalState {progressIssueList: Issue[];@@ -54,33 +52,19 @@ export default {required: true,type: Object as PropType<Project>,},+ databaseList: {+ required: true,+ type: Object as PropType<Database[]>,+ },},setup(props, { emit }) {const store = useStore();- const router = useRouter();const state = reactive<LocalState>({progressIssueList: [],closedIssueList: [],});- const environmentList = computed(() => {- return store.getters["environment/environmentList"](["NORMAL"]);- });-- const databaseList = computed(() => {- const list = store.getters["database/databaseListByProjectId"](- props.project.id- );- return sortDatabaseList(list, environmentList.value);- });-- const prepareDatabaseList = () => {- store.dispatch("database/fetchDatabaseListByProjectId", props.project.id);- };-- watchEffect(prepareDatabaseList);-const prepareIssueList = () => {store.dispatch("issue/fetchIssueList", {@@ -106,7 +90,6 @@ export default {return {state,- databaseList,};},};diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex a8835312ba..dc9a0e7f6f 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -2,7 +2,7 @@<div class="py-2"><ArchiveBanner v-if="project.rowStatus == 'ARCHIVED'" /></div>- <h1 class="px-4 pb-4 text-xl font-bold leading-6 text-main truncate">+ <h1 class="px-6 pb-4 text-xl font-bold leading-6 text-main truncate">{{ project.name }}</h1><BBTabFilter@@ -16,9 +16,20 @@}"/>- <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">+ <div class="max-w-7xl mx-auto py-6 px-6"><template v-if="state.selectedIndex == OVERVIEW_TAB">- <ProjectOverviewPanel id="overview" :project="project" />+ <ProjectOverviewPanel+ id="overview"+ :project="project"+ :databaseList="databaseList"+ />+ </template>+ <template v-if="state.selectedIndex == MIGRATION_HISTORY_TAB">+ <ProjectMigrationHistoryPanel+ id="migration-history"+ :project="project"+ :databaseList="databaseList"+ /></template><template v-else-if="state.selectedIndex == VERSION_CONTROL_TAB"><ProjectVersionControlPanel@@ -38,18 +49,21 @@</template><script lang="ts">-import { computed, onMounted, reactive, watch } from "vue";+import { computed, onMounted, reactive, watch, watchEffect } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";-import { idFromSlug, isProjectOwner } from "../utils";+import { idFromSlug, isProjectOwner, sortDatabaseList } from "../utils";import ArchiveBanner from "../components/ArchiveBanner.vue";+import ProjectMigrationHistoryPanel from "../components/ProjectMigrationHistoryPanel.vue";import ProjectOverviewPanel from "../components/ProjectOverviewPanel.vue";import ProjectVersionControlPanel from "../components/ProjectVersionControlPanel.vue";import ProjectSettingPanel from "../components/ProjectSettingPanel.vue";+import { cloneDeep } from "lodash";const OVERVIEW_TAB = 0;-const VERSION_CONTROL_TAB = 1;-const SETTING_TAB = 2;+const MIGRATION_HISTORY_TAB = 1;+const VERSION_CONTROL_TAB = 2;+const SETTING_TAB = 3;type ProjectTabItem = {name: string;@@ -58,6 +72,7 @@ type ProjectTabItem = {const projectTabItemList: ProjectTabItem[] = [{ name: "Overview", hash: "overview" },+ { name: "Migration History", hash: "migration-history" },{ name: "Version Control", hash: "version-control" },{ name: "Settings", hash: "setting" },];@@ -70,6 +85,7 @@ export default {name: "ProjectDetail",components: {ArchiveBanner,+ ProjectMigrationHistoryPanel,ProjectOverviewPanel,ProjectVersionControlPanel,ProjectSettingPanel,@@ -90,6 +106,29 @@ export default {selectedIndex: OVERVIEW_TAB,});+ const project = computed(() => {+ return store.getters["project/projectById"](+ idFromSlug(props.projectSlug)+ );+ });++ const environmentList = computed(() => {+ return store.getters["environment/environmentList"](["NORMAL"]);+ });++ const prepareDatabaseList = () => {+ store.dispatch("database/fetchDatabaseListByProjectId", project.value.id);+ };++ watchEffect(prepareDatabaseList);++ const databaseList = computed(() => {+ const list = cloneDeep(+ store.getters["database/databaseListByProjectId"](project.value.id)+ );+ return sortDatabaseList(list, environmentList.value);+ });+const selectProjectTabOnHash = () => {if (router.currentRoute.value.hash) {for (let i = 0; i < projectTabItemList.length; i++) {@@ -119,12 +158,6 @@ export default {});- const project = computed(() => {- return store.getters["project/projectById"](- idFromSlug(props.projectSlug)- );- });-// Only the project owner can edit the project general info and configure version control.// This means even the workspace owner won't be able to edit it.// On the other hand, we allow workspace owner to change project membership in case@@ -154,10 +187,12 @@ export default {return {OVERVIEW_TAB,+ MIGRATION_HISTORY_TAB,VERSION_CONTROL_TAB,SETTING_TAB,state,project,+ databaseList,allowEdit,selectTab,projectTabItemList,