Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Transfer in database quick action in project detail page
天舟a9e4e10e4f1d
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex 1d74afac98..4e7760049b 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -351,6 +351,31 @@Default Project</h3></div>++ <div+ v-if="quickAction == 'quickaction.bb.project.database.transfer'"+ class="flex flex-col items-center w-28"+ >+ <button class="btn-icon-primary p-3" @click.prevent="transferDatabase">+ <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="M19 13l-7 7-7-7m14-8l-7 7-7-7"+ ></path>+ </svg>+ </button>+ <h3 class="mt-1 text-center text-base font-normal text-main">+ Transfer in DB+ </h3>+ </div></template></div><BBModal@@ -390,6 +415,16 @@><RequestDatabasePrepForm @dismiss="state.showModal = false" /></template>+ <template+ v-else-if="+ state.quickActionType == 'quickaction.bb.project.database.transfer'+ "+ >+ <TransferDatabaseForm+ :projectId="projectId"+ @dismiss="state.showModal = false"+ />+ </template></BBModal></template>@@ -402,6 +437,7 @@ import InstanceForm from "../components/InstanceForm.vue";import AlterSchemaPrepForm from "../components/AlterSchemaPrepForm.vue";import CreateDatabasePrepForm from "../components/CreateDatabasePrepForm.vue";import RequestDatabasePrepForm from "../components/RequestDatabasePrepForm.vue";+import TransferDatabaseForm from "../components/TransferDatabaseForm.vue";import { DEFAULT_PROJECT_ID, ProjectId, QuickActionType } from "../types";import { idFromSlug } from "../utils";@@ -420,6 +456,7 @@ export default {AlterSchemaPrepForm,CreateDatabasePrepForm,RequestDatabasePrepForm,+ TransferDatabaseForm,},props: {quickActionList: {@@ -462,6 +499,13 @@ export default {});};+ const transferDatabase = () => {+ state.modalTitle = "Transfer in database from other projects";+ state.modalSubtitle = "";+ state.quickActionType = "quickaction.bb.project.database.transfer";+ state.showModal = true;+ };+const createInstance = () => {state.modalTitle = "Create instance";state.modalSubtitle = "";@@ -503,6 +547,7 @@ export default {projectId,createProject,goDefaultProject,+ transferDatabase,createInstance,alterSchema,createDatabase,diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vuenew file mode 100644index 0000000000..b32847a95e--- /dev/null+++ b/frontend/src/components/TransferDatabaseForm.vue@@ -0,0 +1,179 @@+<template>+ <div class="px-4 space-y-6 w-208">+ <div v-if="projectId != DEFAULT_PROJECT_ID" class="textlabel">+ <div v-if="state.transferSource == 'DEFAULT'" class="textinfolabel mb-2">+ Bytebase periodically syncs the instance schema. Newly synced databases+ are first placed in this default project.+ </div>+ <div class="radio-set-row">+ <div class="flex flex-row">+ <div class="radio">+ <input+ tabindex="-1"+ type="radio"+ class="btn"+ value="DEFAULT"+ v-model="state.transferSource"+ />+ <label class="label"> From Default project </label>+ </div>+ </div>+ <div class="radio">+ <input+ tabindex="-1"+ type="radio"+ class="btn"+ value="OTHER"+ v-model="state.transferSource"+ />+ <label class="label"> From other projects </label>+ </div>+ </div>+ </div>++ <DatabaseTable+ :mode="'ALL_SHORT'"+ :bordered="true"+ :customClick="true"+ :databaseList="databaseList"+ @select-database="selectDatabase"+ />++ <!-- Update button group -->+ <div class="pt-4 border-t border-block-border flex justify-end">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="cancel"+ >+ Cancel+ </button>+ </div>++ <BBAlert+ v-if="state.showModal"+ :style="'INFO'"+ :okText="'Transfer'"+ :title="`Are you sure to transfer '${selectedDatabaseName}' into our project?`"+ @ok="+ () => {+ state.showModal = false;+ transferDatabase();+ }+ "+ @cancel="state.showModal = false"+ >+ </BBAlert>+ </div>+</template>++<script lang="ts">+import { computed, PropType, reactive, watchEffect } from "vue";+import { useStore } from "vuex";+import { cloneDeep } from "lodash";+import DatabaseTable from "../components/DatabaseTable.vue";+import { Database, ProjectId, DEFAULT_PROJECT_ID } from "../types";+import { sortDatabaseList } from "../utils";++type TransferSource = "DEFAULT" | "OTHER";++interface LocalState {+ selectedDatabase?: Database;+ transferSource: TransferSource;+ showModal: boolean;+}++export default {+ name: "TransferDatabaseForm",+ emits: ["submit", "dismiss"],+ props: {+ projectId: {+ required: true,+ type: Number as PropType<ProjectId>,+ },+ },+ components: {+ DatabaseTable,+ },+ setup(props, { emit }) {+ const store = useStore();++ const state = reactive<LocalState>({+ transferSource:+ props.projectId == DEFAULT_PROJECT_ID ? "OTHER" : "DEFAULT",+ showModal: false,+ });++ const currentUser = computed(() => store.getters["auth/currentUser"]());++ const prepareDatabaseListForDefaultProject = () => {+ store.dispatch(+ "database/fetchDatabaseListByProjectId",+ DEFAULT_PROJECT_ID+ );+ };++ watchEffect(prepareDatabaseListForDefaultProject);++ const environmentList = computed(() => {+ return store.getters["environment/environmentList"](["NORMAL"]);+ });++ const databaseList = computed(() => {+ var list;+ if (state.transferSource == "DEFAULT") {+ list = cloneDeep(+ store.getters["database/databaseListByProjectId"](DEFAULT_PROJECT_ID)+ );+ } else {+ list = cloneDeep(+ store.getters["database/databaseListByPrincipalId"](+ currentUser.value.id+ )+ ).filter((item: Database) => item.project.id != props.projectId);+ }++ return sortDatabaseList(list, environmentList.value);+ });++ const selectedDatabaseName = computed(() => {+ return state.selectedDatabase?.name;+ });++ const selectDatabase = (database: Database) => {+ state.selectedDatabase = database;+ state.showModal = true;+ };++ const transferDatabase = () => {+ store+ .dispatch("database/transferProject", {+ databaseId: state.selectedDatabase!.id,+ projectId: props.projectId,+ })+ .then((updatedDatabase) => {+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "SUCCESS",+ title: `Successfully transferred '${updatedDatabase.name}' to project '${updatedDatabase.project.name}'.`,+ });+ emit("dismiss");+ });+ };++ const cancel = () => {+ emit("dismiss");+ };++ return {+ DEFAULT_PROJECT_ID,+ state,+ databaseList,+ selectedDatabaseName,+ selectDatabase,+ transferDatabase,+ cancel,+ };+ },+};+</script>diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex f4b2371c06..3bb7b887b2 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -448,6 +448,7 @@ const routes: Array<RouteRecordRaw> = [? ["quickaction.bb.database.schema.update","quickaction.bb.database.create",+ "quickaction.bb.project.database.transfer",]: [];return new Map([diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 3fd4a12983..3dc2d9c504 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -69,7 +69,8 @@ export type EnvironmentQuickActionType =| "quickaction.bb.environment.reorder";export type ProjectQuickActionType =| "quickaction.bb.project.create"- | "quickaction.bb.project.default";+ | "quickaction.bb.project.default"+ | "quickaction.bb.project.database.transfer";export type InstanceQuickActionType = "quickaction.bb.instance.create";export type UserQuickActionType = "quickaction.bb.user.manage";export type DatabaseQuickActionType =