Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(frontend): better notifications when schema/branch editor generated DDL is empty (#10371)
Liu Ji48ce65555525
diff --git a/frontend/src/NotificationContext.vue b/frontend/src/NotificationContext.vueindex 2504950c92..ec6c6dae60 100644--- a/frontend/src/NotificationContext.vue+++ b/frontend/src/NotificationContext.vue@@ -48,25 +48,36 @@ const watchNotification = () => {title: () =>h("div",- { class: "text-sm font-medium text-gray-900 whitespace-pre-wrap mt-1" },+ {+ class: "text-sm font-medium text-gray-900 whitespace-pre-wrap mt-1",+ },item.title),- content: () =>- h(- "div",- { class: "text-sm text-gray-500 whitespace-pre-wrap" },- item.description- ),- meta: () => {- if (!item.link || !item.linkTitle) {- return undefined;- }- return h(- "a",- { href: item.link, class: "normal-link", target: "_blank" },- item.linkTitle- );- },+ content:+ typeof item.description !== "undefined"+ ? () => {+ if (typeof item.description === "function") {+ return item.description();+ }+ if (typeof item.description === "string") {+ return h(+ "div",+ { class: "text-sm text-gray-500 whitespace-pre-wrap" },+ item.description+ );+ }+ }+ : undefined,+ meta:+ item.link && item.linkTitle+ ? () => {+ return h(+ "a",+ { href: item.link, class: "normal-link", target: "_blank" },+ item.linkTitle+ );+ }+ : undefined,});};diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vueindex 87e413fa06..aab8d540be 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue@@ -129,9 +129,9 @@<script lang="ts" setup>import dayjs from "dayjs";import { cloneDeep, head, uniq } from "lodash-es";-import { NTabs, NTabPane } from "naive-ui";-import { computed, onMounted, PropType, reactive, ref, watch } from "vue";-import { useI18n } from "vue-i18n";+import { NTabs, NTabPane, useDialog } from "naive-ui";+import { computed, onMounted, h, PropType, reactive, ref, watch } from "vue";+import { I18nT, useI18n } from "vue-i18n";import { useRouter } from "vue-router";import ActionConfirmModal from "@/components/SchemaEditorV1/Modals/ActionConfirmModal.vue";import { databaseServiceClient } from "@/grpcweb";@@ -153,7 +153,7 @@ import {DatabaseMetadataView,} from "@/types/proto/v1/database_service";import { TenantMode } from "@/types/proto/v1/project_service";-import { TinyTimer, extractProjectResourceName } from "@/utils";+import { TinyTimer, defer, extractProjectResourceName } from "@/utils";import { MonacoEditor } from "../MonacoEditor";import { provideSQLCheckContext } from "../SQLCheck";import SchemaEditorLite, {@@ -213,6 +213,7 @@ const state = reactive<LocalState>({const databaseV1Store = useDatabaseV1Store();const notificationStore = useNotificationStore();const { runSQLCheck } = provideSQLCheckContext();+const $dialog = useDialog();const onUploaderClick = () => {sqlFileUploader.value?.click();@@ -321,6 +322,19 @@ const handleSyncSQLFromSchemaEditor = async () => {const results = Array.from(statementMap.values());state.editStatement = results.map((result) => result.statement).join("\n\n");++ const emptyStatementDatabaseList: ComposedDatabase[] = [];+ for (const [database, result] of statementMap.entries()) {+ if (!result.statement) {+ emptyStatementDatabaseList.push(+ useDatabaseV1Store().getDatabaseByName(database)+ );+ }+ }+ if (emptyStatementDatabaseList.length > 0) {+ // Some of the DDLs are empty+ warnEmptyGeneratedDDL(emptyStatementDatabaseList);+ }};const generateOrGetEditingDDL = async () => {@@ -493,20 +507,25 @@ const handlePreviewIssue = async () => {const databaseIdList = databaseList.value.map((db) => db.uid);const statementList: string[] = [];+ const emptyStatementDatabaseList: ComposedDatabase[] = [];for (const [database, result] of statementMap.entries()) {if (!result.statement) {- pushNotification({- module: "bytebase",- style: "WARN",- title: t("common.warning"),- description: t("schema-editor.nothing-changed-for-database", {- database,- }),- });- return cleanup();+ emptyStatementDatabaseList.push(+ useDatabaseV1Store().getDatabaseByName(database)+ );}statementList.push(result.statement);}+ if (emptyStatementDatabaseList.length > 0) {+ // Some of the DDLs are empty+ if (+ !(await confirmCreateIssueWithEmptyStatement(+ emptyStatementDatabaseList+ ))+ ) {+ return cleanup();+ }+ }if (isBatchMode.value) {query.sql = statementList.join("\n\n");query.name = generateIssueName(@@ -559,4 +578,55 @@ const generateIssueName = (issueNameParts.push(`${datetime} ${tz}`);return issueNameParts.join(" ");};++const renderEmptyGeneratedDDLContent = (databases: ComposedDatabase[]) => {+ const children = databases.map((database) => {+ return h(+ I18nT,+ {+ tag: "li",+ keypath: "schema-editor.nothing-changed-for-database",+ },+ {+ database: database.databaseName,+ }+ );+ });+ return h(+ "ul",+ {+ class: "text-sm space-y-1 max-h-[20rem] overflow-y-auto",+ },+ children+ );+};++const warnEmptyGeneratedDDL = (databases: ComposedDatabase[]) => {+ pushNotification({+ module: "bytebase",+ style: "WARN",+ title: t("common.warning"),+ description: () => renderEmptyGeneratedDDLContent(databases),+ });+};++const confirmCreateIssueWithEmptyStatement = (+ databases: ComposedDatabase[]+) => {+ const d = defer<boolean>();+ $dialog.warning({+ title: t("common.warning"),+ content: () => renderEmptyGeneratedDDLContent(databases),+ style: "z-index: 100000",+ negativeText: t("common.cancel"),+ positiveText: t("common.continue-anyway"),+ onNegativeClick: () => {+ d.resolve(false);+ },+ onPositiveClick: () => {+ d.resolve(true);+ },+ });+ return d.promise;+};</script>diff --git a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vueindex b71397a7c4..a9132878f5 100644--- a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue+++ b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue@@ -122,7 +122,7 @@<script lang="ts" setup>import dayjs from "dayjs";import { cloneDeep } from "lodash-es";-import { NButton } from "naive-ui";+import { NButton, useDialog } from "naive-ui";import { computed, reactive, ref, toRef, watch } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";@@ -151,6 +151,7 @@ import {Sheet_Visibility,} from "@/types/proto/v1/sheet_service";import {+ defer,extractProjectResourceName,extractSheetUID,setSheetStatement,@@ -194,6 +195,7 @@ const {const selectedRolloutObjects = ref<RolloutObject[]>([]);const emptyBranch = Branch.fromJSON({});const isGeneratingDDL = ref(false);+const $dialog = useDialog();const handleSelectEnvironment = (uid: string | undefined) => {if (!uid || uid === String(UNKNOWN_ID)) {@@ -332,6 +334,11 @@ const handlePreviewIssue = async () => {if (errors.length > 0) {return cleanup(errors, fatal);}+ if (statement === "") {+ if (!(await confirmCreateIssueWithEmptyStatement())) {+ return cleanup([], false);+ }+ }const sheet = Sheet.fromPartial({database: db.name,visibility: Sheet_Visibility.VISIBILITY_PROJECT,@@ -382,6 +389,24 @@ const generateIssueName = (databaseName: string) => {return issueNameParts.join(" ");};+const confirmCreateIssueWithEmptyStatement = () => {+ const d = defer<boolean>();+ $dialog.warning({+ title: t("common.warning"),+ content: t("schema-editor.generated-ddl-is-empty"),+ style: "z-index: 100000",+ negativeText: t("common.cancel"),+ positiveText: t("common.continue-anyway"),+ onNegativeClick: () => {+ d.resolve(false);+ },+ onPositiveClick: () => {+ d.resolve(true);+ },+ });+ return d.promise;+};+watch(() => props.branch,() => {diff --git a/frontend/src/components/SchemaEditorLite/algorithm/apply-selected.ts b/frontend/src/components/SchemaEditorLite/algorithm/apply-selected.tsindex f8ff5b2948..83736357b5 100644--- a/frontend/src/components/SchemaEditorLite/algorithm/apply-selected.ts+++ b/frontend/src/components/SchemaEditorLite/algorithm/apply-selected.ts@@ -13,7 +13,11 @@ import { filterColumnMetadata, filterTableMetadata } from "@/utils";import { SchemaEditorContext } from "../context";import { keyForResource, keyForResourceName } from "../context/common";import { RolloutObject } from "../types";-import { buildColumnConfigMap, buildColumnMap } from "./utils";+import {+ buildColumnConfigMap,+ buildColumnMap,+ cleanupUnusedConfigs,+} from "./utils";export const useApplySelectedMetadataEdit = (context: SchemaEditorContext) => {const { getTableStatus, getColumnStatus } = context;@@ -170,6 +174,8 @@ export const useApplySelectedMetadataEdit = (context: SchemaEditorContext) => {}}target.schemaConfigs = schemaConfigs;++ cleanupUnusedConfigs(target);};return { applySelectedMetadataEdit };diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 204293e35b..010c43534b 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -271,7 +271,8 @@"nothing-changed": "Nothing changed","untitled": "Untitled","nickname": "Nickname",- "missing-permission": "Missing required permissions"+ "missing-permission": "Missing required permissions",+ "continue-anyway": "Continue anyway"},"error-page": {"go-back-home": "Go back home"diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 15935415b3..29be4da1cd 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -271,7 +271,8 @@"nothing-changed": "nada ha cambiado","untitled": "Intitulado","nickname": "Apodo",- "missing-permission": "Faltan permisos requeridos"+ "missing-permission": "Faltan permisos requeridos",+ "continue-anyway": "De todas maneras, continúe"},"error-page": {"go-back-home": "Volver al inicio"diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex d72065f9ca..e6fd394250 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -269,7 +269,8 @@"nothing-changed": "没有改变","untitled": "未命名","nickname": "昵称",- "missing-permission": "缺少必需的权限"+ "missing-permission": "缺少必需的权限",+ "continue-anyway": "仍要继续"},"error-page": {"go-back-home": "回到主页"diff --git a/frontend/src/types/notification.ts b/frontend/src/types/notification.tsindex e94ff086f2..d45a6e8817 100644--- a/frontend/src/types/notification.ts+++ b/frontend/src/types/notification.ts@@ -1,3 +1,5 @@+import { VNodeChild } from "vue";+export type BBNotificationStyle = "INFO" | "SUCCESS" | "WARN" | "CRITICAL";export type Notification = {@@ -6,7 +8,7 @@ export type Notification = {module: string;style: BBNotificationStyle;title: string;- description?: string;+ description?: string | (() => VNodeChild);link?: string;linkTitle?: string;manualHide?: boolean;