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: support select table template in branching (#8737)
ecmadaoc8d0f5ed7e08
diff --git a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vueindex ef1275b2dd..5e9e13ef66 100644--- a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue+++ b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue@@ -208,6 +208,7 @@ const treeData = computed(() => {return treeNodeList;});+const contextMenuOptions = computed(() => {const treeNode = contextMenu.treeNode;if (isUndefined(treeNode)) {@@ -580,6 +581,7 @@ const openTabForTable = (treeNode: TreeNode) => {parentName: branchSchema.value.branch.name,schemaId: treeNode.schemaId,tableId: treeNode.tableId,+ name: treeNode.label,});} else if (treeNode.type === "schema") {const index = expandedKeysRef.value.findIndex(@@ -588,6 +590,12 @@ const openTabForTable = (treeNode: TreeNode) => {if (index < 0) {expandedKeysRef.value.push(treeNode.key);}+ schemaEditorV1Store.addTab({+ id: generateUniqueTabId(),+ type: SchemaEditorTabType.TabForDatabase,+ parentName: branchSchema.value.branch.name,+ name: treeNode.label,+ });}state.shouldRelocateTreeNode = true;diff --git a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vueindex 7f04c4ca9d..ec21ca703a 100644--- a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue+++ b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue@@ -689,6 +689,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {id: generateUniqueTabId(),type: SchemaEditorTabType.TabForDatabase,parentName: treeNode.database,+ name: treeNode.label,});} else if (treeNode.type === "schema") {const index = expandedKeysRef.value.findIndex(@@ -704,6 +705,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {parentName: treeNode.database,schemaId: treeNode.schemaId,tableId: treeNode.tableId,+ name: treeNode.label,});}diff --git a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vueindex fe09d5f81b..b55348297e 100644--- a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue+++ b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue@@ -138,6 +138,7 @@ const handleConfirmButtonClick = async () => {parentName: props.parentName,schemaId: props.schemaId,tableId: tableEdit.id,+ name: state.tableName,});} else {const table = schema.tableList.find((table) => table.id === props.tableId);diff --git a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vueindex 12519d7844..41d0935b18 100644--- a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue+++ b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue@@ -19,6 +19,7 @@/></div><button+ v-if="!readonly"class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60":disabled="!allowCreateTable"@click="handleCreateNewTable"@@ -27,6 +28,7 @@{{ $t("schema-editor.actions.create-table") }}</button><button+ v-if="!readonly"class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60":disabled="!allowCreateTable"@click="state.showSchemaTemplateDrawer = true"@@ -112,10 +114,7 @@:classification="table.classification":classification-config="classificationConfig"/>- <div- v-if="!editorStore.readonly && !disableChangeTable(table)"- class="flex"- >+ <div v-if="!readonly && !disableChangeTable(table)" class="flex"><buttonv-if="table.classification"class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"@@ -162,6 +161,7 @@{{ table.userComment }}</div><div+ v-if="!readonly"class="bb-grid-cell table-item-cell !px-0.5 flex justify-start items-center":class="getTableClassList(table, row)">@@ -251,7 +251,6 @@ import { Drawer, DrawerContent } from "@/components/v2";import {hasFeature,generateUniqueTabId,- useDatabaseV1Store,useSettingV1Store,useSchemaEditorV1Store,} from "@/store";@@ -262,6 +261,7 @@ import {TableMetadata,} from "@/types/proto/v1/database_service";import { SchemaTemplateSetting_TableTemplate } from "@/types/proto/v1/setting_service";+import { emptyDatabase } from "@/types/v1/database";import {Table,DatabaseTabContext,@@ -305,7 +305,9 @@ interface LocalState {const { t } = useI18n();const editorStore = useSchemaEditorV1Store();const settingStore = useSettingV1Store();-const currentTab = computed(() => editorStore.currentTab as DatabaseTabContext);+const currentTab = computed(+ () => (editorStore.currentTab || {}) as DatabaseTabContext+);const state = reactive<LocalState>({selectedSubtab: "table-list",selectedSchemaId: "",@@ -315,18 +317,21 @@ const state = reactive<LocalState>({showSchemaTemplateDrawer: false,showClassificationDrawer: false,});-const databaseSchema = computed(() => {- return editorStore.resourceMap["database"].get(- currentTab.value.parentName- ) as DatabaseSchema;-});-const database = computed(() => databaseSchema.value.database);-const databaseV1 = computed(() => {- return useDatabaseV1Store().getDatabaseByUID(database.value.uid);-});-const databaseEngine = computed(() => database.value.instanceEntity.engine);+const databaseV1 = computed(+ () => editorStore.currentDatabase ?? emptyDatabase()+);+const readonly = computed(() => editorStore.readonly);++const databaseEngine = computed(() => databaseV1.value?.instanceEntity.engine);const schemaList = computed(() => {- return databaseSchema.value.schemaList;+ return editorStore.currentSchemaList;+});+const databaseSchema = computed((): DatabaseSchema => {+ return {+ database: databaseV1.value,+ schemaList: schemaList.value,+ originSchemaList: [],+ };});const selectedSchema = computed(() => {return schemaList.value.find(@@ -464,6 +469,7 @@ const tableHeaderList = computed(() => {{title: "",width: "30px",+ hide: readonly.value,},].filter((header) => !header.hide);});@@ -502,7 +508,7 @@ const handleCreateNewTable = () => {);if (selectedSchema) {state.tableNameModalContext = {- parentName: database.value.name,+ parentName: currentTab.value.parentName,schemaId: selectedSchema.id,tableName: undefined,};@@ -513,19 +519,24 @@ const handleTableItemClick = (table: Table) => {editorStore.addTab({id: generateUniqueTabId(),type: SchemaEditorTabType.TabForTable,- parentName: database.value.name,+ parentName: currentTab.value.parentName,schemaId: state.selectedSchemaId,tableId: table.id,+ name: table.name,});};const handleDropTable = (table: Table) => {- editorStore.dropTable(database.value.uid, state.selectedSchemaId, table.id);+ editorStore.dropTable(+ currentTab.value.parentName,+ state.selectedSchemaId,+ table.id+ );};const handleRestoreTable = (table: Table) => {editorStore.restoreTable(- database.value.uid,+ currentTab.value.parentName,state.selectedSchemaId,table.id);@@ -597,9 +608,10 @@ const handleApplyTemplate = (template: SchemaTemplateSetting_TableTemplate) => {editorStore.addTab({id: generateUniqueTabId(),type: SchemaEditorTabType.TabForTable,- parentName: database.value.name,+ parentName: currentTab.value.parentName,schemaId: state.selectedSchemaId,tableId: tableEdit.id,+ name: template.table.name,});}};diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vueindex 8bb186c6ed..0f967afb2b 100644--- a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue+++ b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue@@ -321,6 +321,7 @@ const gotoForeignKeyReferencedTable = (column: Column) => {parentName: currentTab.value.parentName,schemaId: referencedSchema.id,tableId: referencedTable.id,+ name: referencedTable.name,});nextTick(() => {diff --git a/frontend/src/components/SchemaEditorV1/TabsContainer.vue b/frontend/src/components/SchemaEditorV1/TabsContainer.vueindex 34ca1b24e2..e9f75818a0 100644--- a/frontend/src/components/SchemaEditorV1/TabsContainer.vue+++ b/frontend/src/components/SchemaEditorV1/TabsContainer.vue@@ -135,6 +135,9 @@ const getTabComputedClassList = (tab: TabContext) => {};const getTabName = (tab: TabContext) => {+ if (tab.name) {+ return tab.name;+ }if (tab.type === SchemaEditorTabType.TabForDatabase) {const database = schemaEditorV1Store.databaseList.find((database) => database.name === tab.parentNamediff --git a/frontend/src/store/modules/v1/schemaEditor.ts b/frontend/src/store/modules/v1/schemaEditor.tsindex 783f5b859d..8132d3982e 100644--- a/frontend/src/store/modules/v1/schemaEditor.ts+++ b/frontend/src/store/modules/v1/schemaEditor.ts@@ -11,6 +11,8 @@ import {SchemaEditorTabType,TableTabContext,} from "@/types/v1/schemaEditor";+import { Schema } from "@/types/v1/schemaEditor/atomType";+import { useDatabaseV1Store } from "./database";export const generateUniqueTabId = () => {return uniqueId();@@ -51,6 +53,32 @@ export const useSchemaEditorV1Store = defineStore("SchemaEditorV1", {(databaseSchema) => databaseSchema.database);},+ currentDatabase(): ComposedDatabase | undefined {+ if (!this.currentTab) {+ return;+ }+ if (this.resourceType === "branch") {+ const baselineDatabase = this.resourceMap.branch.get(+ this.currentTab.parentName+ )?.branch.baselineDatabase;+ if (!baselineDatabase) {+ return;+ }+ return useDatabaseV1Store().getDatabaseByName(baselineDatabase);+ } else {+ return this.resourceMap.database.get(this.currentTab.parentName)+ ?.database;+ }+ },+ currentSchemaList(): Schema[] {+ if (!this.currentTab) {+ return [] as Schema[];+ }+ return (+ this.resourceMap[this.resourceType].get(this.currentTab.parentName)+ ?.schemaList ?? []+ );+ },},actions: {getCurrentEngine(parentName: string) {diff --git a/frontend/src/types/v1/schemaEditor/state.ts b/frontend/src/types/v1/schemaEditor/state.tsindex 10c5cb834c..3ef6384b4f 100644--- a/frontend/src/types/v1/schemaEditor/state.ts+++ b/frontend/src/types/v1/schemaEditor/state.ts@@ -26,7 +26,9 @@ export interface TableTabContext {tableId: string;}-export type TabContext = DatabaseTabContext | TableTabContext;+export type TabContext = {+ name?: string;+} & (DatabaseTabContext | TableTabContext);export interface DatabaseSchema {database: ComposedDatabase;