Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): (WIP) gh-ost integration part.3 - issue creation (#1152)
Liu Ji58c31151e0dd
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vueindex bc91db23e5..ec18a9ac8b 100644--- a/frontend/src/components/Issue/IssueDetailLayout.vue+++ b/frontend/src/components/Issue/IssueDetailLayout.vue@@ -61,7 +61,7 @@:selected-stage="selectedStage":selected-task="selectedTask"class="border-t border-b"- @select-stage-id="selectStageId"+ @select-stage="selectStageId"@select-task="selectTask"/></template>@@ -305,6 +305,7 @@ import {UpdateSchemaContext,UpdateSchemaDetail,TaskDatabaseSchemaUpdateGhostSyncPayload,+ UpdateSchemaGhostContext,} from "../../types";import {defaulTemplate as defaultTemplate,@@ -483,7 +484,18 @@ export default defineComponent({const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {if (props.create) {- selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;+ if (isGhostMode.value) {+ // In gh-ost mode, when creating an issue, all sub-tasks in a stage+ // share the same earliestAllowedTs.+ // So updates on any one of them will be applied to others.+ // (They can be updated independently after creation)+ const taskList = selectedStage.value.taskList as TaskCreate[];+ taskList.forEach((task) => {+ task.earliestAllowedTs = newEarliestAllowedTsMs;+ });+ } else {+ selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;+ }} else {const taskPatch: TaskPatch = {earliestAllowedTs: newEarliestAllowedTsMs,@@ -540,11 +552,27 @@ export default defineComponent({migrationType: taskList[0].migrationType!,updateSchemaDetailList: detailList,};+ } else if (isGhostMode.value) {+ // for gh-ost mode, copy user edited tasks back to issue.createContext+ // only the first subtask (bb.task.database.schema.update.ghost.sync) has statement+ const stageList = issue.pipeline!.stageList;+ const createContext = issue.createContext as UpdateSchemaGhostContext;+ const detailList = createContext.updateSchemaDetailList;+ stageList.forEach((stage, i) => {+ const detail = detailList[i];+ const syncTask = stage.taskList[0];++ detail.databaseId = syncTask.databaseId!;+ detail.databaseName = syncTask.databaseName!;+ detail.statement = syncTask.statement;+ detail.earliestAllowedTs = syncTask.earliestAllowedTs;+ });} else {// for multi-tenancy issue pipeline (M * N)// createContext is up-to-date already// so nothing to do}+// then empty issue.pipeline and issue.payload// because we are no longer passing parameters via issue.pipeline// we are using issue.createContext insteaddiff --git a/frontend/src/components/Issue/PipelineGhostFlow.vue b/frontend/src/components/Issue/PipelineGhostFlow.vueindex e7bea31081..0f31056743 100644--- a/frontend/src/components/Issue/PipelineGhostFlow.vue+++ b/frontend/src/components/Issue/PipelineGhostFlow.vue@@ -1,6 +1,6 @@<template><div class="w-full">- <div class="lg:flex divide-y lg:divide-y-0 border-b">+ <div class="lg:flex lg:items-center divide-y lg:divide-y-0 border-b"><divv-for="(stage, i) in pipeline.stageList":key="i"@@ -15,17 +15,22 @@/><divclass="text cursor-pointer hover:underline hidden lg:ml-4 lg:flex lg:flex-col"+ @click.prevent="onClickStage(stage, i)"><span class="text-xs">{{ stage.name }}</span><span class="text-sm">{{ taskNameOfStage(stage) }}</span></div><divclass="text ml-4 cursor-pointer flex items-center space-x-2 lg:hidden"+ @click.prevent="onClickStage(stage, i)"><span class="text-sm min-w-32">{{ stage.name }}</span><span class="text-sm flex-1">{{ taskNameOfStage(stage) }}</span></div>- <div class="tooltip-wrapper">+ <div+ class="tooltip-wrapper"+ @click.prevent="onClickStage(stage, i)"+ ><span class="tooltip whitespace-nowrap">Missing SQL statement</span>@@ -175,6 +180,7 @@ const props = defineProps({const emit = defineEmits<{(e: "select-task", stageIdOrIndex: number, taskSlug: string): void;+ (e: "select-stage", stageIdOrIndex: number): void;}>();const { t } = useI18n();@@ -279,8 +285,16 @@ const getTaskProgress = (task: Task | TaskCreate) => {return 0;}if (task.type !== "bb.task.database.schema.update.ghost.sync") return 0;- const progress = 66.6; // TODO(jim): not implemented yet- return progress;+ const taskRun = (task as Task).taskRunList.find((run) => {+ // TODO(Jim): find the correct taskRun which indicates the sync progress.+ return false;+ });+ if (taskRun) {+ // TODO(Jim): get progress from taskRun.result.detail+ }++ // nothing found+ return 0;};const stageClass = (stage: Stage | StageCreate): string[] => {@@ -303,6 +317,15 @@ const taskClass = (task: Task | TaskCreate): string[] => {return classes;};+const onClickStage = (stage: Stage | StageCreate, index: number) => {+ if (props.create) {+ emit("select-stage", index);+ return;+ }+ const { id } = stage as Stage;+ emit("select-stage", id);+};+const onClickTask = (stageId: number, taskName: string, taskId: number) => {const ts = taskSlug(taskName, taskId);emit("select-task", stageId, ts);diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vueindex 95d11013d2..834477167a 100644--- a/frontend/src/views/IssueDetail.vue+++ b/frontend/src/views/IssueDetail.vue@@ -28,7 +28,7 @@ import {Ref,} from "vue";import { useRoute, _RouteLocationBase } from "vue-router";-import { idFromSlug } from "../utils";+import { idFromSlug, isDBAOrOwner } from "../utils";import { IssueDetailLayout } from "../components/Issue";import {UNKNOWN_ID,@@ -45,6 +45,7 @@ import {TaskDatabaseSchemaUpdatePayload,Principal,UpdateSchemaContext,+ UpdateSchemaGhostContext,} from "../types";import {defaulTemplate as defaultTemplate,@@ -60,6 +61,7 @@ import {useCurrentUser,useDatabaseStore,useIssueStore,+ usePrincipalStore,useProjectStore,} from "@/store";@@ -157,6 +159,22 @@ export default defineComponent({return project;};+ const findDatabaseListByQuery = (): Database[] => {+ // route.query.databaseList is comma-splitted databaseId list+ // e.g. databaseList=7002,7006,7014+ const databaseList: Database[] = [];+ if (route.query.databaseList) {+ const databaseIdList = (route.query.databaseList as string).split(",");+ const databaseStore = useDatabaseStore();+ for (const databaseId of databaseIdList) {+ databaseList.push(+ databaseStore.getDatabaseById(parseInt(databaseId, 10))+ );+ }+ }+ return databaseList;+ };+const buildNewTenantSchemaUpdateIssue = async (): Promise<IssueCreate> => {const helper = new IssueCreateHelper({template: newIssueTemplate,@@ -201,19 +219,9 @@ export default defineComponent({});await helper.prepare();- const databaseList: Database[] = [];- if (route.query.databaseList) {- const databaseIdList = (route.query.databaseList as string).split(",");- const databaseStore = useDatabaseStore();- for (const databaseId of databaseIdList) {- databaseList.push(- databaseStore.getDatabaseById(parseInt(databaseId, 10))- );- }- }// standard single-stage or multi-stage issue is generated by specifying// databaseId for each stage-+ const databaseList = findDatabaseListByQuery();const templateType = route.query.template as TemplateType;let migrationType: MigrationType = "MIGRATE";if (templateType === "bb.issue.database.data.update") {@@ -245,11 +253,41 @@ export default defineComponent({return helper.generate();};+ const buildNewGhostIssue = async (): Promise<IssueCreate> => {+ const helper = new IssueCreateHelper({+ template: newIssueTemplate,+ currentUser,+ issueStore,+ route,+ });+ await helper.prepare();++ helper.issueCreate!.type = "bb.issue.database.schema.update.ghost";++ const databaseList = findDatabaseListByQuery();+ const createContext: UpdateSchemaGhostContext = {+ updateSchemaDetailList: databaseList.map((db) => {+ return {+ databaseId: db.id,+ databaseName: db.name,+ statement: VALIDATE_ONLY_SQL,+ earliestAllowedTs: 0,+ };+ }),+ };++ helper.issueCreate!.createContext = createContext;++ await helper.validate();++ return helper.generate();+ };+const maybeBuildTenantDeployIssue = async (): Promise<- IssueCreate | false+ IssueCreate | undefined> => {if (route.query.mode !== "tenant") {- return false;+ return undefined;}const project = await findProject();@@ -260,7 +298,18 @@ export default defineComponent({if (project.tenantMode === "TENANT" && isMigrate) {return buildNewTenantSchemaUpdateIssue();}- return false;+ return undefined;+ };++ const maybeBuildGhostIssue = async (): Promise<IssueCreate | undefined> => {+ if (parseInt(route.query.ghost as string, 10) !== 1) {+ return undefined;+ }+ const issueType = route.query.template as IssueType;+ if (issueType !== "bb.issue.database.schema.update") {+ return undefined;+ }+ return buildNewGhostIssue();};const buildNewIssue = async (): Promise<IssueCreate | undefined> => {@@ -269,6 +318,11 @@ export default defineComponent({return tenant;}+ const ghost = await maybeBuildGhostIssue();+ if (ghost) {+ return ghost;+ }+// Create issue from normal query parameterconst newIssue = await buildNewStandardIssue();@@ -389,6 +443,16 @@ class IssueCreateHelper {this.issue = null;}+ findDBAOrOwner(): Principal {+ const currentUser = this.context.currentUser.value;+ if (isDBAOrOwner(currentUser.role)) return currentUser;++ const userList = usePrincipalStore().principalList;++ // In bytebase, we always have at least 1 DBA or Owner, so it's safe here.+ return userList.find((user) => isDBAOrOwner(user.role))!;+ }+async prepare(): Promise<IssueCreate> {const { template, currentUser, route } = this.context;const actuatorStore = useActuatorStore();@@ -411,7 +475,7 @@ class IssueCreateHelper {// validateOnly does not support assigneeId=-1// so we need to specify here// but will reset this to -1 if route.query.assignee is empty- assigneeId: currentUser.value.id,+ assigneeId: this.findDBAOrOwner().id,createContext: {},payload: {},};