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): support creating issues via UI for projects using VCS workflow (#4667)
Liu Jib682e2875d89
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vueindex 2fb50e2c18..8eca1ce57b 100644--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue@@ -187,15 +187,7 @@ import { NTabs, NTabPane } from "naive-ui";import { useEventListener } from "@vueuse/core";import { cloneDeep } from "lodash-es";import DatabaseTable from "../DatabaseTable.vue";-import {- baseDirectoryWebUrl,- Database,- DatabaseId,- Project,- ProjectId,- Repository,- UNKNOWN_ID,-} from "@/types";+import { Database, DatabaseId, Project, ProjectId, UNKNOWN_ID } from "@/types";import {allowGhostMigration,allowUsingSchemaEditor,@@ -208,7 +200,6 @@ import {useDatabaseStore,useEnvironmentList,useProjectStore,- useRepositoryStore,} from "@/store";import ProjectStandardView, {State as ProjectStandardState,@@ -246,7 +237,6 @@ const router = useRouter();const currentUser = useCurrentUser();const projectStore = useProjectStore();-const repositoryStore = useRepositoryStore();const ghostDialog = ref<InstanceType<typeof GhostDialog>>();const schemaEditorContext = ref<{@@ -265,7 +255,7 @@ const state = reactive<LocalState>({project: props.projectId? projectStore.getProjectById(props.projectId): undefined,- alterType: "SINGLE_DB",+ alterType: "MULTI_DB",selectedDatabaseIdListForEnvironment: new Map(),selectedDatabaseIdListForTenantMode: new Set<number>(),deployingTenantDatabaseList: [],@@ -493,123 +483,90 @@ const generateTenant = async () => {if (project.id === UNKNOWN_ID) return;- if (project.workflowType === "UI") {- const query: Record<string, any> = {- template: props.type,- project: project.id,- mode: "tenant",- };- if (state.alterType === "TENANT") {- const databaseList = useDatabaseStore().getDatabaseListByProjectId(- project.id+ const query: Record<string, any> = {+ template: props.type,+ project: project.id,+ mode: "tenant",+ };+ if (state.alterType === "TENANT") {+ const databaseList = useDatabaseStore().getDatabaseListByProjectId(+ project.id+ );+ if (isAlterSchema.value && allowUsingSchemaEditor(databaseList)) {+ schemaEditorContext.value.databaseIdList = databaseList.map(+ (database) => database.id);- if (isAlterSchema.value && allowUsingSchemaEditor(databaseList)) {- schemaEditorContext.value.databaseIdList = databaseList.map(- (database) => database.id- );- state.showSchemaEditorModal = true;- return;- }- // In tenant deploy pipeline, we use project name instead of database name- // if more than one databases are to be deployed.- const name =- databaseList.length > 1 ? project.name : databaseList[0].name;- query.name = generateIssueName([name], false);- query.databaseName = "";- } else {- const databaseList: Database[] = [];- const databaseStore = useDatabaseStore();- for (const databaseId of state.selectedDatabaseIdListForTenantMode) {- databaseList.push(databaseStore.getDatabaseById(databaseId));- }- if (isAlterSchema.value && allowUsingSchemaEditor(databaseList)) {- schemaEditorContext.value.databaseIdList = Array.from(- state.selectedDatabaseIdListForTenantMode.values()- );- state.showSchemaEditorModal = true;- return;- }-- query.name = generateIssueName(- databaseList.map((database) => database.name),- false+ state.showSchemaEditorModal = true;+ return;+ }+ // In tenant deploy pipeline, we use project name instead of database name+ // if more than one databases are to be deployed.+ const name = databaseList.length > 1 ? project.name : databaseList[0].name;+ query.name = generateIssueName([name], false);+ query.databaseName = "";+ } else {+ const databaseList: Database[] = [];+ const databaseStore = useDatabaseStore();+ for (const databaseId of state.selectedDatabaseIdListForTenantMode) {+ databaseList.push(databaseStore.getDatabaseById(databaseId));+ }+ if (isAlterSchema.value && allowUsingSchemaEditor(databaseList)) {+ schemaEditorContext.value.databaseIdList = Array.from(+ state.selectedDatabaseIdListForTenantMode.values());- query.databaseList = Array.from(- state.selectedDatabaseIdListForTenantMode- ).join(",");+ state.showSchemaEditorModal = true;+ return;}- emit("dismiss");-- router.push({- name: "workspace.issue.detail",- params: {- issueSlug: "new",- },- query,- });- } else if (project.workflowType === "VCS") {- repositoryStore- .fetchRepositoryByProjectId(project.id)- .then((repository: Repository) => {- window.open(- baseDirectoryWebUrl(repository, {- TYPE:- props.type === "bb.issue.database.schema.update" ? "ddl" : "dml",- }),- "_blank"- );- });- emit("dismiss");+ query.name = generateIssueName(+ databaseList.map((database) => database.name),+ false+ );+ query.databaseList = Array.from(+ state.selectedDatabaseIdListForTenantMode+ ).join(",");}++ emit("dismiss");++ router.push({+ name: "workspace.issue.detail",+ params: {+ issueSlug: "new",+ },+ query,+ });};const selectDatabase = async (database: Database) => {- if (database.project.workflowType == "UI") {- if (isAlterSchema.value && allowUsingSchemaEditor([database])) {- schemaEditorContext.value.databaseIdList = [database.id];- state.showSchemaEditorModal = true;- return;- }+ if (isAlterSchema.value && allowUsingSchemaEditor([database])) {+ schemaEditorContext.value.databaseIdList = [database.id];+ state.showSchemaEditorModal = true;+ return;+ }- const mode = await isUsingGhostMigration([database]);- if (mode === false) {- return;- }- emit("dismiss");-- const query: Record<string, any> = {- template: props.type,- name: generateIssueName([database.name], mode === "online"),- project: database.project.id,- databaseList: database.id,- };- if (mode === "online") {- query.ghost = "1";- }- router.push({- name: "workspace.issue.detail",- params: {- issueSlug: "new",- },- query,- });- } else if (database.project.workflowType == "VCS") {- repositoryStore- .fetchRepositoryByProjectId(database.project.id)- .then((repository: Repository) => {- window.open(- baseDirectoryWebUrl(repository, {- DB_NAME: database.name,- ENV_NAME: database.instance.environment.name,- TYPE:- props.type === "bb.issue.database.schema.update" ? "ddl" : "dml",- }),- "_blank"- );- });- emit("dismiss");+ const mode = await isUsingGhostMigration([database]);+ if (mode === false) {+ return;+ }+ emit("dismiss");++ const query: Record<string, any> = {+ template: props.type,+ name: generateIssueName([database.name], mode === "online"),+ project: database.project.id,+ databaseList: database.id,+ };+ if (mode === "online") {+ query.ghost = "1";}+ router.push({+ name: "workspace.issue.detail",+ params: {+ issueSlug: "new",+ },+ query,+ });};const cancel = () => {diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vueindex a940b6eef1..e0a9f312ba 100644--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue@@ -126,7 +126,7 @@<script lang="ts">/* eslint-disable vue/no-mutating-props */-import { defineComponent, watch, PropType, computed } from "vue";+import { defineComponent, PropType, computed } from "vue";import { NCollapse, NCollapseItem } from "naive-ui";import {@@ -170,25 +170,6 @@ export default defineComponent({},emits: ["select-database"],setup(props, { emit }) {- // MULTI_DB now supports selecting one database, which can be a replacement- // of SINGLE_DB.- // So SINGLE_DB is only needed and available for VCS workflow.- // And we won't provide a radio button group for single/multi selection in- // the future.- watch(- () => props.project?.workflowType,- (type) => {- if (type === "VCS") {- props.state.alterType = "SINGLE_DB";- } else {- props.state.alterType = "MULTI_DB";- }- },- {- immediate: true,- }- );-const databaseListGroupByEnvironment = computed(() => {const listByEnv = props.environmentList.map((environment) => {const databaseList = props.databaseList.filter(diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vueindex 456813edcd..2938d37787 100644--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue@@ -72,7 +72,7 @@</template><button- v-if="shouldShowStatementEditButton"+ v-if="shouldShowStatementEditButtonForUI"type="button"class="btn-icon"@click.prevent="beginEdit"@@ -99,9 +99,7 @@</button></template>- <template- v-if="!create && (issue as Issue).project.workflowType === 'VCS'"- >+ <template v-if="shouldShowVirtualStatementEditButtonForVCS"><!--Show a virtual pencil icon in VCS workflow which opens a guidewhen clicked.@@ -197,7 +195,7 @@ import { TableMetadata } from "@/types/proto/store/database";import MonacoEditor from "../MonacoEditor/MonacoEditor.vue";import IssueRollbackButton from "./IssueRollbackButton.vue";import { isUndefined } from "lodash-es";-import { useInstanceEditorLanguage } from "@/utils";+import { isTaskTriggeredByVCS, useInstanceEditorLanguage } from "@/utils";import { useSQLAdviceMarkers } from "./logic/useSQLAdviceMarkers";interface LocalState {@@ -405,7 +403,7 @@ const isTaskHasSheetId = computed(() => {return !isUndefined(sheetIdOfTask(task as Task));});-const shouldShowStatementEditButton = computed(() => {+const shouldShowStatementEditButtonForUI = computed(() => {if (create.value) {return false;}@@ -416,8 +414,34 @@ const shouldShowStatementEditButton = computed(() => {if (state.editing) {return false;}+ if (!allowEditStatement.value) {+ return false;+ }++ // If a task is triggered by VCS commit, we are NOT allowed to edit its+ // SQL statements directly from UI, until we solved the edit and write-back+ // problems.+ const task = selectedTask.value as Task;+ if (isTaskTriggeredByVCS(task)) {+ return false;+ }++ return true;+});- return allowEditStatement.value;+const shouldShowVirtualStatementEditButtonForVCS = computed(() => {+ if (shouldShowStatementEditButtonForUI.value) {+ // This is mutual exclusive to another button for UI.+ return false;+ }+ if (create.value) {+ return false;+ }+ if (!allowEditStatement.value) {+ return false;+ }+ const task = selectedTask.value as Task;+ return isTaskTriggeredByVCS(task);});onMounted(() => {diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.tsindex ef6c2fc3b0..f414fcc67e 100644--- a/frontend/src/components/Issue/logic/common.ts+++ b/frontend/src/components/Issue/logic/common.ts@@ -34,7 +34,7 @@ import {SheetId,} from "@/types";import { useIssueLogic } from "./index";-import { isDev, taskCheckRunSummary } from "@/utils";+import { isDev, isTaskTriggeredByVCS, taskCheckRunSummary } from "@/utils";export const useCommonLogic = () => {const { create, issue, selectedTask, createIssue, onStatusChanged } =@@ -146,14 +146,15 @@ export const useCommonLogic = () => {// if not creating, we are allowed to edit sql statement only when:// 1. issue.status is OPEN// 2. AND currentUser is the creator- // 3. AND workflowType is UIif (issueEntity.status !== "OPEN") {return false;}if (issueEntity.creator.id !== currentUser.value.id) {- return false;- }- if (issueEntity.project.workflowType !== "UI") {+ if (isTaskTriggeredByVCS(selectedTask.value as Task)) {+ // If an issue is triggered by VCS, its creator will be 1 (SYSTEM_BOT_ID)+ // We should "Allow" current user to edit the statement (via VCS).+ return true;+ }return false;}diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.tsindex 905eb149e3..619afd00c8 100644--- a/frontend/src/utils/database.ts+++ b/frontend/src/utils/database.ts@@ -3,10 +3,7 @@ import type {DataSourceType,Environment,Principal,- Repository,} from "../types";-import { baseDirectoryWebUrl } from "../types";-import { useRepositoryStore } from "@/store";import { hasWorkspacePermission } from "./role";import { isDev, semverCompare } from "./util";@@ -147,22 +144,3 @@ export function isArchivedDatabase(db: Database): boolean {}return false;}--export const alterSchemaVCS = (database: Database) => {- const { project } = database;- if (project.workflowType === "VCS") {- useRepositoryStore()- .fetchRepositoryByProjectId(database.project.id)- .then((repository: Repository): void => {- window.open(- baseDirectoryWebUrl(repository, {- DB_NAME: database.name,- ENV_NAME: database.instance.environment.name,- TYPE: "ddl",- }),- "_blank"- );- });- return;- }-};diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.tsindex 91dff40fb6..2d64272146 100644--- a/frontend/src/utils/task.ts+++ b/frontend/src/utils/task.ts@@ -6,7 +6,13 @@ import {Task,TaskCreate,TaskDatabaseCreatePayload,+ TaskDatabaseDataUpdatePayload,TaskDatabasePITRRestorePayload,+ TaskDatabaseSchemaBaselinePayload,+ TaskDatabaseSchemaUpdateGhostSyncPayload,+ TaskDatabaseSchemaUpdatePayload,+ TaskDatabaseSchemaUpdateSDLPayload,+ TaskType,unknown,} from "@/types";import { issueSlug, stageSlug, taskSlug } from "./slug";@@ -146,3 +152,30 @@ export const isTaskSkipped = (task: Task): boolean => {}return false;};++export const isTaskTriggeredByVCS = (task: Task): boolean => {+ const taskTypesWithPushEvent: TaskType[] = [+ "bb.task.database.data.update",+ "bb.task.database.schema.update",+ "bb.task.database.schema.update-sdl",+ "bb.task.database.schema.update.ghost.sync",+ "bb.task.database.schema.baseline",+ ];++ type PayloadTypesWithPushEvent =+ | TaskDatabaseDataUpdatePayload+ | TaskDatabaseSchemaUpdatePayload+ | TaskDatabaseSchemaUpdateSDLPayload+ | TaskDatabaseSchemaUpdateGhostSyncPayload+ | TaskDatabaseSchemaBaselinePayload;++ if (taskTypesWithPushEvent.includes(task.type)) {+ const payload = task.payload as PayloadTypesWithPushEvent | undefined;++ if (payload && payload.pushEvent) {+ return true;+ }+ }++ return false;+};diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vueindex 8cc41edf8a..83ac4fd573 100644--- a/frontend/src/views/DatabaseDetail.vue+++ b/frontend/src/views/DatabaseDetail.vue@@ -135,11 +135,7 @@class="btn-normal"@click="createMigration('bb.issue.database.data.update')">- <span>{{ changeDataText }}</span>- <heroicons-outline:external-link- v-if="database.project.workflowType == 'VCS'"- class="-mr-1 ml-2 h-5 w-5 text-control-light"- />+ <span>{{ $t("database.change-data") }}</span></button><buttonv-if="allowAlterSchema"@@ -147,11 +143,7 @@class="btn-normal"@click="createMigration('bb.issue.database.schema.update')">- <span>{{ alterSchemaText }}</span>- <heroicons-outline:external-link- v-if="database.project.workflowType == 'VCS'"- class="-mr-1 ml-2 h-5 w-5 text-control-light"- />+ <span>{{ $t("database.alter-schema") }}</span></button></div></div>@@ -328,8 +320,6 @@ import {ProjectId,UNKNOWN_ID,DEFAULT_PROJECT_ID,- Repository,- baseDirectoryWebUrl,Database,DatabaseLabel,SQLResultSet,@@ -345,7 +335,6 @@ import {useDatabaseStore,useDBSchemaStore,usePolicyByDatabaseAndType,- useRepositoryStore,useSQLStore,} from "@/store";import dayjs from "dayjs";@@ -379,7 +368,6 @@ const props = defineProps({const { t } = useI18n();const router = useRouter();const databaseStore = useDatabaseStore();-const repositoryStore = useRepositoryStore();const dbSchemaStore = useDBSchemaStore();const sqlStore = useSQLStore();const ghostDialog = ref<InstanceType<typeof GhostDialog>>();@@ -541,20 +529,6 @@ const allowEditDatabaseLabels = computed((): boolean => {return allowAdmin.value;});-const alterSchemaText = computed(() => {- if (database.value.project.workflowType == "VCS") {- return t("database.alter-schema-in-vcs");- }- return t("database.alter-schema");-});--const changeDataText = computed(() => {- if (database.value.project.workflowType == "VCS") {- return t("database.change-data-in-vcs");- }- return t("database.change-data");-});-const tabItemList = computed((): BBTabFilterItem[] => {if (database.value.instance.engine === "SPANNER" ||@@ -602,66 +576,52 @@ const isUsingGhostMigration = async (databaseList: Database[]) => {const createMigration = async (type: "bb.issue.database.schema.update" | "bb.issue.database.data.update") => {- if (database.value.project.workflowType == "UI") {- let mode: "online" | "normal" | false = "normal";- if (type === "bb.issue.database.schema.update") {- if (allowUsingSchemaEditor([database.value])) {- state.showSchemaEditorModal = true;- return;- }-- // Check and show a normal/online selection modal dialog if needed.- mode = await isUsingGhostMigration([database.value]);- }- if (mode === false) return;-- // Create a user friendly default issue name- const issueNameParts: string[] = [];- issueNameParts.push(`[${database.value.name}]`);- if (mode === "online") {- issueNameParts.push("Online schema change");- } else {- issueNameParts.push(- type === "bb.issue.database.schema.update"- ? `Alter schema`- : `Change data`- );- }- const datetime = dayjs().format("@MM-DD HH:mm");- const tz = "UTC" + dayjs().format("ZZ");- issueNameParts.push(`${datetime} ${tz}`);-- const query: Record<string, any> = {- template: type,- name: issueNameParts.join(" "),- project: database.value.project.id,- databaseList: database.value.id,- };- if (mode === "online") {- query.ghost = "1";+ type AlterMode = "online" | "normal" | false;+ let mode: AlterMode = "normal";+ if (type === "bb.issue.database.schema.update") {+ if (allowUsingSchemaEditor([database.value])) {+ state.showSchemaEditorModal = true;+ return;}- router.push({- name: "workspace.issue.detail",- params: {- issueSlug: "new",- },- query,- });- } else if (database.value.project.workflowType == "VCS") {- repositoryStore- .fetchRepositoryByProjectId(database.value.project.id)- .then((repository: Repository) => {- window.open(- baseDirectoryWebUrl(repository, {- DB_NAME: database.value.name,- ENV_NAME: database.value.instance.environment.name,- TYPE: type === "bb.issue.database.schema.update" ? "ddl" : "dml",- }),- "_blank"- );- });+ // Check and show a normal/online selection modal dialog if needed.+ mode = await isUsingGhostMigration([database.value]);}+ if (mode === false) return;++ // Create a user friendly default issue name+ const issueNameParts: string[] = [];+ issueNameParts.push(`[${database.value.name}]`);+ if (mode === "online") {+ issueNameParts.push("Online schema change");+ } else {+ issueNameParts.push(+ type === "bb.issue.database.schema.update"+ ? `Alter schema`+ : `Change data`+ );+ }+ const datetime = dayjs().format("@MM-DD HH:mm");+ const tz = "UTC" + dayjs().format("ZZ");+ issueNameParts.push(`${datetime} ${tz}`);++ const query: Record<string, any> = {+ template: type,+ name: issueNameParts.join(" "),+ project: database.value.project.id,+ databaseList: database.value.id,+ };+ if (mode === "online") {+ query.ghost = "1";+ }++ router.push({+ name: "workspace.issue.detail",+ params: {+ issueSlug: "new",+ },+ query,+ });};const updateProject = (newProjectId: ProjectId, labels?: DatabaseLabel[]) => {diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vueindex f970c961b1..7fbca998a5 100644--- a/frontend/src/views/sql-editor/SQLEditorPage.vue+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue@@ -95,7 +95,7 @@ import EditorPanel from "./EditorPanel/EditorPanel.vue";import TerminalPanel from "./TerminalPanel/TerminalPanel.vue";import TabList from "./TabList";import TablePanel from "./TablePanel/TablePanel.vue";-import { alterSchemaVCS, isDatabaseAccessible } from "@/utils";+import { isDatabaseAccessible } from "@/utils";import AdminModeButton from "./EditorCommon/AdminModeButton.vue";import SchemaEditorModal from "@/components/AlterSchemaPrepForm/SchemaEditorModal.vue";@@ -149,13 +149,7 @@ const alterSchemaState = reactive<AlterSchemaState>({const handleAlterSchema = async (params: { databaseId: DatabaseId }) => {const { databaseId } = params;const database = databaseStore.getDatabaseById(databaseId);- const project = await useProjectStore().getOrFetchProjectById(- database.project.id- );- if (project.workflowType === "VCS") {- alterSchemaVCS(database);- return;- }+ await useProjectStore().getOrFetchProjectById(database.project.id);alterSchemaState.databaseIdList = [databaseId];alterSchemaState.showModal = true;};