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: add field template in schema design (#7543)
ecmadao313011cf9008
diff --git a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vueindex abb6b5fc31..f393b33b91 100644--- a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue+++ b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue@@ -97,6 +97,7 @@<script lang="ts" setup>import { head, isNull, isUndefined } from "lodash-es";+import { NEllipsis } from "naive-ui";import { computed, onMounted, reactive, ref, watch } from "vue";import { InstanceV1EngineIcon } from "@/components/v2";import {@@ -173,6 +174,8 @@ onMounted(async () => {} catch (error) {// do nothing.}+ } else if (props.baselineSchema?.projectId) {+ state.projectId = props.baselineSchema.projectId;}});@@ -262,6 +265,7 @@ const handleDatabaseSelect = async (databaseId: string) => {if (!database) {return;}+const environment = environmentStore.getEnvironmentByName(database.effectiveEnvironment);diff --git a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vueindex 48a561bfad..c0a7e98943 100644--- a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue+++ b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue@@ -3,6 +3,7 @@:show="true"width="auto":auto-focus="false"+ :trap-focus="false":close-on-esc="true"@update:show="(show: boolean) => !show && emit('dismiss')">@@ -98,7 +99,7 @@ interface LocalState {schemaDesign: SchemaDesign;}-defineProps({+const props = defineProps({projectId: {type: String,default: undefined,@@ -115,7 +116,9 @@ const databaseStore = useDatabaseV1Store();const schemaDesignStore = useSchemaDesignStore();const state = reactive<LocalState>({schemaDesignName: "",- baselineSchema: {},+ baselineSchema: {+ projectId: props.projectId,+ },schemaDesign: SchemaDesign.fromPartial({}),});const refreshId = ref<string>("");diff --git a/frontend/src/components/SchemaDesigner/Designer.vue b/frontend/src/components/SchemaDesigner/Designer.vueindex 1028384cbf..67924987b5 100644--- a/frontend/src/components/SchemaDesigner/Designer.vue+++ b/frontend/src/components/SchemaDesigner/Designer.vue@@ -14,6 +14,8 @@<script lang="ts" setup>import { computed } from "vue";+import TableEditor from "./Panels/TableEditor.vue";+import TabsContainer from "./TabsContainer.vue";import { SchemaDesignerTabType, useSchemaDesignerContext } from "./common";const { getCurrentTab } = useSchemaDesignerContext();diff --git a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vueindex b953ae16d9..a990d5ee24 100644--- a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue+++ b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue@@ -14,6 +14,15 @@<heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />{{ $t("schema-editor.actions.add-column") }}</button>+ <button+ class="flex flex-row justify-center items-center border px-3 py-1 leading-6 text-sm text-gray-700 rounded cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"+ :disabled="disableChangeTable"+ @click="state.showSchemaTemplateDrawer = true"+ >+ <FeatureBadge feature="bb.feature.schema-template" />+ <heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />+ {{ $t("schema-editor.actions.add-from-template") }}+ </button></div></div><div class="flex justify-end items-center">@@ -260,6 +269,22 @@:column-id="editForeignKeyColumn.id"@close="state.showEditColumnForeignKeyModal = false"/>++ <Drawer+ :show="state.showSchemaTemplateDrawer"+ @close="state.showSchemaTemplateDrawer = false"+ >+ <DrawerContent :title="$t('schema-template.field-template.self')">+ <div class="w-[calc(100vw-36rem)] min-w-[64rem] max-w-[calc(100vw-8rem)]">+ <FieldTemplates :engine="engine" @apply="handleApplyColumnTemplate" />+ </div>+ </DrawerContent>+ </Drawer>+ <FeatureModal+ feature="bb.feature.schema-template"+ :open="state.showFeatureModal"+ @cancel="state.showFeatureModal = false"+ /></template><script lang="ts" setup>@@ -270,9 +295,15 @@ import { computed, nextTick, reactive, ref } from "vue";import { useI18n } from "vue-i18n";import { BBCheckbox, BBSpin } from "@/bbkit";import HighlightCodeBlock from "@/components/HighlightCodeBlock";-import { generateUniqueTabId, useSettingV1Store } from "@/store/modules";+import { Drawer, DrawerContent } from "@/components/v2";+import {+ hasFeature,+ generateUniqueTabId,+ useSettingV1Store,+} from "@/store/modules";import { ColumnMetadata } from "@/types/proto/store/database";import { Engine } from "@/types/proto/v1/common";+import { SchemaTemplateSetting_FieldTemplate } from "@/types/proto/v1/setting_service";import {Column,Table,@@ -281,6 +312,7 @@ import {ForeignKey,} from "@/types/schemaEditor/atomType";import { getDataTypeSuggestionList } from "@/utils";+import FieldTemplates from "@/views/SchemaTemplate/FieldTemplates.vue";import EditColumnForeignKeyModal from "../Modals/EditColumnForeignKeyModal.vue";import {SchemaDesignerTabType,@@ -296,6 +328,8 @@ interface LocalState {isFetchingDDL: boolean;statement: string;showEditColumnForeignKeyModal: boolean;+ showSchemaTemplateDrawer: boolean;+ showFeatureModal: boolean;}const { t } = useI18n();@@ -309,6 +343,8 @@ const state = reactive<LocalState>({isFetchingDDL: false,statement: "",showEditColumnForeignKeyModal: false,+ showSchemaTemplateDrawer: false,+ showFeatureModal: false,});const schema = computed(() => {@@ -529,6 +565,31 @@ const handleAddColumn = () => {});};+const handleApplyColumnTemplate = (+ template: SchemaTemplateSetting_FieldTemplate+) => {+ if (!hasFeature("bb.feature.schema-template")) {+ state.showFeatureModal = true;+ return;+ }+ if (template.engine !== engine.value || !template.column) {+ return;+ }+ const column = convertColumnMetadataToColumn(+ ColumnMetadata.fromPartial({+ name: template.column.name,+ type: template.column.type,+ nullable: template.column.nullable,+ comment: template.column.comment,+ userComment: template.column.userComment,+ default: template.column.default,+ })+ );+ column.status = "created";+ table.value.columnList.push(column);+ state.showSchemaTemplateDrawer = false;+};+const handleColumnDefaultFieldChange = (column: Column,defaultString: stringdiff --git a/frontend/src/components/SchemaDesigner/PrepForm/index.vue b/frontend/src/components/SchemaDesigner/PrepForm/index.vueindex fa424678fc..2893867e5b 100644--- a/frontend/src/components/SchemaDesigner/PrepForm/index.vue+++ b/frontend/src/components/SchemaDesigner/PrepForm/index.vue@@ -34,6 +34,7 @@<CreateSchemaDesignPanelv-if="state.showCreatePanel"+ :project-id="projectId"@dismiss="state.showCreatePanel = false"@created="(schemaDesign) => {@@ -65,6 +66,10 @@ interface LocalState {selectedSchemaDesignName?: string;}+defineProps<{+ projectId?: string;+}>();+const { schemaDesignList, ready } = useSchemaDesignList();const state = reactive<LocalState>({showCreatePanel: false,