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: put diff and generated DDL in separate tabs (#5956)
Liu Ji196800650307
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex c4ab9fe7d4..81265852bc 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1187,7 +1187,9 @@"no-difference-tip": "No diff found.","more-version": "more...","character-sets-diff-found": "There are differences between character sets.",- "preview-issue": "Preview issue"+ "preview-issue": "Preview issue",+ "schema-change": "Schema change",+ "generated-ddl-statement": "Generated DDL statement"},"sensitive": "Sensitive","access-denied": "You don't have the permission to access this database.",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 73213d9943..83ce3547b1 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1185,7 +1185,9 @@"no-difference-tip": "No se encontraron diferencias.","more-version": "más...","character-sets-diff-found": "Hay diferencias entre los juegos de caracteres.",- "preview-issue": "Vista previa de incidencia"+ "preview-issue": "Vista previa de incidencia",+ "schema-change": "cambio de esquema",+ "generated-ddl-statement": "Declaración DDL generada"},"sensitive": "Sensible","access-denied": "No tiene permiso para acceder a esta base de datos.",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 120d1f6036..47076cb400 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1185,7 +1185,8 @@"no-difference-tip": "没有发现差异","more-version": "更多...","character-sets-diff-found": "Schema 之间的字符集不同",- "preview-issue": "预览工单"+ "preview-issue": "预览工单",+ "schema-change": "Schema 变化"},"sensitive": "敏感","access-denied": "您没有访问该数据库的权限",diff --git a/frontend/src/views/SyncDatabaseSchema/DiffViewPanel.vue b/frontend/src/views/SyncDatabaseSchema/DiffViewPanel.vuenew file mode 100644index 0000000000..b573ddd1ff--- /dev/null+++ b/frontend/src/views/SyncDatabaseSchema/DiffViewPanel.vue@@ -0,0 +1,98 @@+<template>+ <NTabs v-model:value="tab">+ <NTabPane name="diff" :label="$t('database.sync-schema.schema-change')">+ <div class="w-full flex flex-row justify-start items-center mb-2">+ <span>{{ previewSchemaChangeMessage }}</span>+ </div>+ <code-diff+ v-show="shouldShowDiff"+ class="code-diff-container w-full h-auto max-h-96 overflow-y-auto border rounded"+ :old-string="targetDatabaseSchema"+ :new-string="sourceDatabaseSchema"+ output-format="side-by-side"+ />+ <div+ v-show="!shouldShowDiff"+ class="w-full h-auto px-3 py-2 overflow-y-auto border rounded"+ >+ <p>+ {{ $t("database.sync-schema.message.no-diff-found") }}+ </p>+ </div>+ </NTabPane>++ <NTabPane+ name="ddl"+ :label="$t('database.sync-schema.generated-ddl-statement')"+ >+ <div class="w-full flex flex-col justify-start mb-2">+ <div class="flex flex-row justify-start items-center">+ <span>{{ $t("database.sync-schema.synchronize-statements") }}</span>+ <button+ type="button"+ class="btn-icon ml-2"+ @click.prevent="$emit('copy-statement')"+ >+ <heroicons-outline:clipboard class="h-5 w-5" />+ </button>+ </div>+ <div class="textinfolabel">+ {{ $t("database.sync-schema.synchronize-statements-description") }}+ </div>+ </div>+ <MonacoEditor+ ref="editorRef"+ class="w-full h-auto max-h-96 border rounded"+ :value="statement"+ :auto-focus="false"+ :dialect="dialectOfEngine(engineType)"+ @change="onStatementChange"+ @ready="updateEditorHeight"+ />+ </NTabPane>+ </NTabs>+</template>++<script lang="ts" setup>+import { computed, ref } from "vue";+import { CodeDiff } from "v-code-diff";+import { NTabs, NTabPane } from "naive-ui";++import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";+import { Database, dialectOfEngine } from "@/types";++const props = defineProps<{+ statement: string;+ sourceDatabase: Database;+ targetDatabaseSchema: string;+ sourceDatabaseSchema: string;+ shouldShowDiff: boolean;+ previewSchemaChangeMessage: string;+}>();++const $emit = defineEmits<{+ (event: "statement-change", statement: string): void;+ (event: "copy-statement"): void;+}>();++const tab = ref<"diff" | "ddl">("diff");+const editorRef = ref<InstanceType<typeof MonacoEditor>>();++const engineType = computed(() => {+ return props.sourceDatabase.instance.engine;+});++const updateEditorHeight = () => {+ const contentHeight =+ editorRef.value?.editorInstance?.getContentHeight() as number;+ const actualHeight = contentHeight;+ editorRef.value?.setEditorContentHeight(actualHeight);+};++const onStatementChange = (statement: string) => {+ $emit("statement-change", statement);+ requestAnimationFrame(() => {+ updateEditorHeight();+ });+};+</script>diff --git a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vueindex df51da06f1..bbf80805e9 100644--- a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue+++ b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue@@ -148,60 +148,24 @@</div></div><div class="w-3/4 grow h-full">- <main ref="diffViewerRef" class="p-4 w-full h-full overflow-y-auto">+ <main ref="diffViewerRef" class="p-2 w-full h-full overflow-y-auto"><divv-show="selectedDatabase"class="w-full h-auto flex flex-col justify-start items-start">- <div class="w-full flex flex-row justify-start items-center mb-2">- <span>{{ previewSchemaChangeMessage }}</span>- </div>- <code-diff- v-show="shouldShowDiff"- class="code-diff-container w-full h-auto max-h-96 overflow-y-auto border rounded"- :old-string="targetDatabaseSchema"- :new-string="sourceDatabaseSchema"- output-format="side-by-side"- />- <div- v-show="!shouldShowDiff"- class="w-full h-auto px-3 py-2 overflow-y-auto border rounded"- >- <p>- {{ $t("database.sync-schema.message.no-diff-found") }}- </p>- </div>- <div class="w-full flex flex-col justify-start mt-4 mb-2 leading-8">- <div class="flex flex-row justify-start items-center">- <span>{{- $t("database.sync-schema.synchronize-statements")- }}</span>- <button- type="button"- class="btn-icon ml-2"- @click.prevent="copyStatement"- >- <heroicons-outline:clipboard class="h-5 w-5" />- </button>- </div>- <div class="textinfolabel">- {{- $t("database.sync-schema.synchronize-statements-description")- }}- </div>- </div>- <MonacoEditor- ref="editorRef"- class="w-full h-auto max-h-96 border rounded"- :value="+ <DiffViewPanel+ :statement="state.selectedDatabaseId? databaseDiffCache[state.selectedDatabaseId].edited: ''"- :auto-focus="false"- :dialect="dialectOfEngine(engineType)"- @change="onStatementChange"- @ready="updateEditorHeight"+ :source-database="sourceDatabase"+ :target-database-schema="targetDatabaseSchema"+ :source-database-schema="sourceDatabaseSchema"+ :should-show-diff="shouldShowDiff"+ :preview-schema-change-message="previewSchemaChangeMessage"+ @statement-change="onStatementChange"+ @copy-statement="onCopyStatement"/></div><div@@ -241,7 +205,6 @@ import axios from "axios";import { head, isEqual } from "lodash-es";import { NEllipsis } from "naive-ui";import { PropType, computed, onMounted, reactive, ref, watch } from "vue";-import { CodeDiff } from "v-code-diff";import { useI18n } from "vue-i18n";import {pushNotification,@@ -257,12 +220,11 @@ import {MigrationHistory,ProjectId,UNKNOWN_ID,- dialectOfEngine,} from "@/types";import { migrationHistorySlug } from "@/utils";import TargetDatabasesSelectPanel from "./TargetDatabasesSelectPanel.vue";-import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";import InstanceEngineIcon from "@/components/InstanceEngineIcon.vue";+import DiffViewPanel from "./DiffViewPanel.vue";interface SourceSchema {environmentId: EnvironmentId;@@ -294,7 +256,6 @@ const projectStore = useProjectStore();const environmentStore = useEnvironmentStore();const databaseStore = useDatabaseStore();const diffViewerRef = ref<HTMLDivElement>();-const editorRef = ref<InstanceType<typeof MonacoEditor>>();const state = reactive<LocalState>({isLoading: true,showDatabaseWithDiff: true,@@ -322,9 +283,6 @@ const environment = computed(() => {const sourceDatabase = computed(() => {return databaseStore.getDatabaseById(props.sourceSchema.databaseId);});-const engineType = computed(() => {- return sourceDatabase.value.instance.engine;-});const sourceDatabaseSchema = computed(() => {return props.sourceSchema.migrationHistory.schema || "";});@@ -344,7 +302,7 @@ const selectedDatabase = computed(() => {: undefined;});const shouldShowDiff = computed(() => {- return (+ return !!(state.selectedDatabaseId &&databaseDiffCache[state.selectedDatabaseId]?.raw !== "");@@ -397,7 +355,7 @@ const handleUnselectDatabase = (database: Database) => {}};-const copyStatement = () => {+const onCopyStatement = () => {const editStatement = state.selectedDatabaseId? databaseSchemaCache[state.selectedDatabaseId]: "";@@ -414,17 +372,9 @@ const copyStatement = () => {const onStatementChange = (value: string) => {if (state.selectedDatabaseId) {databaseDiffCache[state.selectedDatabaseId].edited = value;- updateEditorHeight();}};-const updateEditorHeight = () => {- const contentHeight =- editorRef.value?.editorInstance?.getContentHeight() as number;- const actualHeight = contentHeight;- editorRef.value?.setEditorContentHeight(actualHeight);-};-watch(() => state.selectedDatabaseId,() => {