Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: update table level classification (#8787)

boojack5cb44ddc0f53
diff --git a/backend/api/v1/schema_design_transformer.go b/backend/api/v1/schema_design_transformer.go
index 7f57118879..12e3557096 100644
--- a/backend/api/v1/schema_design_transformer.go
+++ b/backend/api/v1/schema_design_transformer.go
@@ -167,6 +167,7 @@ type tableState struct {
columns map[string]*columnState
indexes map[string]*indexState
foreignKeys map[string]*foreignKeyState
+ comment string
}
func (t *tableState) removeUnsupportedIndex() {
@@ -243,7 +244,17 @@ func (t *tableState) toString(buf *strings.Builder) error {
}
}
- if _, err := buf.WriteString("\n);\n"); err != nil {
+ if _, err := buf.WriteString("\n)"); err != nil {
+ return err
+ }
+
+ if t.comment != "" {
+ if _, err := buf.WriteString(fmt.Sprintf(" COMMENT='%s'", t.comment)); err != nil {
+ return err
+ }
+ }
+
+ if _, err := buf.WriteString(";\n"); err != nil {
return err
}
return nil
@@ -261,6 +272,7 @@ func newTableState(id int, name string) *tableState {
func convertToTableState(id int, table *v1pb.TableMetadata) *tableState {
state := newTableState(id, table.Name)
+ state.comment = table.Comment
for i, column := range table.Columns {
state.columns[column.Name] = convertToColumnState(i, column)
}
diff --git a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
index 5e9e13ef66..26aa92292a 100644
--- a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
+++ b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
@@ -165,45 +165,27 @@ const tableList = computed(() =>
);
const treeData = computed(() => {
const treeNodeList: TreeNode[] = [];
- if (engine.value === Engine.MYSQL || engine.value === Engine.TIDB) {
- const schema = schemaList.value[0];
- if (!schema) {
- return;
- }
- for (const table of tableList.value) {
- const tableTreeNode: TreeNodeForTable = {
+ for (const schema of schemaList.value) {
+ const schemaTreeNode: TreeNodeForSchema = {
+ type: "schema",
+ key: `s-${schema.id}`,
+ label: schema.name,
+ isLeaf: false,
+ schemaId: schema.id,
+ children: schema.tableList.map((table) => ({
type: "table",
key: `t-${schema.id}-${table.id}`,
label: table.name,
+ children: [],
isLeaf: true,
schemaId: schema.id,
tableId: table.id,
- };
- treeNodeList.push(tableTreeNode);
- }
- } else {
- for (const schema of schemaList.value) {
- const schemaTreeNode: TreeNodeForSchema = {
- type: "schema",
- key: `s-${schema.id}`,
- label: schema.name,
- isLeaf: false,
- schemaId: schema.id,
- children: schema.tableList.map((table) => ({
- type: "table",
- key: `t-${schema.id}-${table.id}`,
- label: table.name,
- children: [],
- isLeaf: true,
- schemaId: schema.id,
- tableId: table.id,
- })),
- };
- if (schemaTreeNode.children!.length === 0) {
- schemaTreeNode.isLeaf = true;
- }
- treeNodeList.push(schemaTreeNode);
+ })),
+ };
+ if (schemaTreeNode.children!.length === 0) {
+ schemaTreeNode.isLeaf = true;
}
+ treeNodeList.push(schemaTreeNode);
}
return treeNodeList;
@@ -347,12 +329,16 @@ const renderPrefix = ({ option }: { option: TreeOption }) => {
const renderLabel = ({ option }: { option: TreeOption }) => {
const treeNode = option as TreeNode;
const additionalClassList: string[] = ["select-none"];
+ let label = treeNode.label;
if (treeNode.type === "schema") {
const schema = schemaList.value.find(
(schema) => schema.id === treeNode.schemaId
);
if (schema) {
+ if (engine.value !== Engine.POSTGRES) {
+ label = "Tables";
+ }
if (schema.status === "created") {
additionalClassList.push("text-green-700");
} else if (schema.status === "dropped") {
@@ -396,7 +382,7 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
() => [
h("span", {
innerHTML: getHighlightHTMLByKeyWords(
- escape(treeNode.label),
+ escape(label),
escape(searchPattern.value)
),
}),
@@ -496,7 +482,7 @@ const renderSuffix = ({ option }: { option: TreeOption }) => {
}
return icons;
}
- throw new Error(`Unknown tree node type`);
+ return null;
};
const getOriginalName = (name: string): string => {
diff --git a/frontend/src/components/SchemaEditorV1/Editor.vue b/frontend/src/components/SchemaEditorV1/Editor.vue
index ad09937075..704c49e25c 100644
--- a/frontend/src/components/SchemaEditorV1/Editor.vue
+++ b/frontend/src/components/SchemaEditorV1/Editor.vue
@@ -28,14 +28,14 @@ import DatabaseEditor from "./Panels/DatabaseEditor.vue";
import TableEditor from "./Panels/TableEditor.vue";
import TabsContainer from "./TabsContainer.vue";
-const schemaEditorV1Store = useSchemaEditorV1Store();
-const currentTab = computed(() => schemaEditorV1Store.currentTab);
-
interface LocalState {
tableSearchPattern: string;
columnSearchPattern: string;
}
+const schemaEditorV1Store = useSchemaEditorV1Store();
+const currentTab = computed(() => schemaEditorV1Store.currentTab);
+
const state = reactive<LocalState>({
tableSearchPattern: "",
columnSearchPattern: "",
@@ -49,8 +49,8 @@ const handleColumnSearchPattern = (columnSearchPattern: string) => {
state.columnSearchPattern = columnSearchPattern;
};
-watch([() => state.tableSearchPattern, () => currentTab.value], () => {
- // state.tableSearchPattern = "";
+watch([() => currentTab.value], () => {
+ state.tableSearchPattern = "";
state.columnSearchPattern = "";
});
</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
index 67e81be987..30598968a6 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
@@ -72,120 +72,10 @@
<!-- List view -->
<template v-if="state.selectedSubtab === 'table-list'">
- <!-- table list -->
- <BBGrid
- class="border"
- :column-list="tableHeaderList"
- :data-source="shownTableList"
- :custom-header="true"
- :row-clickable="false"
- >
- <template #header>
- <div role="table-row" class="bb-grid-row bb-grid-header-row group">
- <div
- v-for="(header, index) in tableHeaderList"
- :key="index"
- role="table-cell"
- class="bb-grid-header-cell"
- >
- {{ header.title }}
- </div>
- </div>
- </template>
- <template #item="{ item: table, row }: { item: Table, row: number }">
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- <NEllipsis
- class="w-full cursor-pointer leading-6 my-2 hover:text-accent"
- >
- <span @click="handleTableItemClick(table)">
- {{ table.name }}
- </span>
- </NEllipsis>
- </div>
- <div
- v-if="supportClassification"
- class="bb-grid-cell table-item-cell flex items-center gap-x-2 text-sm"
- :class="getTableClassList(table, row)"
- >
- <ClassificationLevelBadge
- :classification="table.classification"
- :classification-config="classificationConfig"
- />
- <div v-if="!readonly && !disableChangeTable(table)" class="flex">
- <button
- v-if="table.classification"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="table.classification = ''"
- >
- <heroicons-outline:x class="w-3 h-3" />
- </button>
- <button
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="showClassificationDrawer(table)"
- >
- <heroicons-outline:pencil class="w-3 h-3" />
- </button>
- </div>
- </div>
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- {{ table.rowCount }}
- </div>
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- {{ bytesToString(table.dataSize) }}
- </div>
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- {{ table.engine }}
- </div>
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- {{ table.collation }}
- </div>
- <div
- class="bb-grid-cell table-item-cell"
- :class="getTableClassList(table, row)"
- >
- {{ 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)"
- >
- <NTooltip v-if="!isDroppedTable(table)" trigger="hover" to="body">
- <template #trigger>
- <heroicons:trash
- class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
- @click="handleDropTable(table)"
- />
- </template>
- <span>{{ $t("schema-editor.actions.drop-table") }}</span>
- </NTooltip>
- <NTooltip v-else trigger="hover" to="body">
- <template #trigger>
- <heroicons:arrow-uturn-left
- class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
- @click="handleRestoreTable(table)"
- />
- </template>
- <span>{{ $t("schema-editor.actions.restore") }}</span>
- </NTooltip>
- </div>
- </template>
- </BBGrid>
+ <TableList
+ :schema-id="selectedSchema?.id || ''"
+ :table-list="shownTableList"
+ />
</template>
<template v-else-if="state.selectedSubtab === 'schema-diagram'">
<SchemaDiagram
@@ -217,7 +107,7 @@
<DrawerContent :title="$t('schema-template.table-template.self')">
<div class="w-[calc(100vw-36rem)] min-w-[64rem] max-w-[calc(100vw-8rem)]">
<TableTemplates
- :engine="databaseEngine"
+ :engine="engine"
:readonly="true"
@apply="handleApplyTemplate"
/>
@@ -242,10 +132,8 @@
<script lang="ts" setup>
import { head } from "lodash-es";
-import { NEllipsis, NTooltip } from "naive-ui";
import scrollIntoView from "scroll-into-view-if-needed";
import { computed, nextTick, reactive, watch } from "vue";
-import { useI18n } from "vue-i18n";
import { SchemaDiagram, SchemaDiagramIcon } from "@/components/SchemaDiagram";
import { Drawer, DrawerContent } from "@/components/v2";
import {
@@ -269,11 +157,10 @@ import {
SchemaEditorTabType,
convertTableMetadataToTable,
} from "@/types/v1/schemaEditor";
-import { bytesToString, isDev } from "@/utils";
import TableTemplates from "@/views/SchemaTemplate/TableTemplates.vue";
import TableNameModal from "../Modals/TableNameModal.vue";
-import { isTableChanged } from "../utils";
import { useMetadataForDiagram } from "../utils/useMetadataForDiagram";
+import TableList from "./TableList.vue";
const props = withDefaults(
defineProps<{
@@ -289,8 +176,6 @@ type SubtabType = "table-list" | "schema-diagram";
interface LocalState {
selectedSubtab: SubtabType;
selectedSchemaId: string;
- isFetchingDDL: boolean;
- statement: string;
showFeatureModal: boolean;
showSchemaTemplateDrawer: boolean;
showClassificationDrawer: boolean;
@@ -302,17 +187,12 @@ interface LocalState {
activeTableId?: string;
}
-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: "",
- isFetchingDDL: false,
- statement: "",
+ selectedSchemaId: currentTab.value?.selectedSchemaId ?? "",
showFeatureModal: false,
showSchemaTemplateDrawer: false,
showClassificationDrawer: false,
@@ -321,8 +201,9 @@ const databaseV1 = computed(
() => editorStore.currentDatabase ?? emptyDatabase()
);
const readonly = computed(() => editorStore.readonly);
-
-const databaseEngine = computed(() => databaseV1.value?.instanceEntity.engine);
+const engine = computed(() => {
+ return editorStore.getCurrentEngine(currentTab.value.parentName);
+});
const schemaList = computed(() => {
return editorStore.currentSchemaList;
});
@@ -354,56 +235,12 @@ const classificationConfig = computed(() => {
editorStore.project.dataClassificationConfigId
);
});
-const disableChangeTable = (table: Table): boolean => {
- return (
- selectedSchema.value?.status === "dropped" || table.status === "dropped"
- );
-};
-
-const getTableClassList = (table: Table, index: number): string[] => {
- const classList = [];
- if (table.status === "dropped") {
- classList.push("text-red-700 !bg-red-50 opacity-70");
- } else if (table.status === "created") {
- classList.push("text-green-700 !bg-green-50");
- } else if (
- isTableChanged(
- currentTab.value.parentName,
- state.selectedSchemaId,
- table.id
- )
- ) {
- classList.push("text-yellow-700 !bg-yellow-50");
- }
- if (index % 2 === 1) {
- classList.push("bg-gray-50");
- }
- return classList;
-};
-
-const showClassificationDrawer = (table: Table) => {
- state.activeTableId = table.id;
- state.showClassificationDrawer = true;
-};
-
-const onClassificationSelect = (classificationId: string) => {
- state.showClassificationDrawer = false;
- const table = tableList.value.find(
- (table) => table.id === state.activeTableId
- );
- if (!table) {
- return;
- }
- table.classification = classificationId;
- state.activeTableId = undefined;
-};
-
const shouldShowSchemaSelector = computed(() => {
- return databaseEngine.value === Engine.POSTGRES;
+ return engine.value === Engine.POSTGRES;
});
const allowCreateTable = computed(() => {
- if (databaseEngine.value === Engine.POSTGRES) {
+ if (engine.value === Engine.POSTGRES) {
return (
schemaList.value.length > 0 &&
selectedSchema.value &&
@@ -424,56 +261,6 @@ const schemaSelectorOptionList = computed(() => {
return optionList;
});
-const supportClassification = computed(() => {
- return classificationConfig.value && isDev();
-});
-
-const tableHeaderList = computed(() => {
- return [
- {
- key: "name",
- title: t("schema-editor.database.name"),
- width: "minmax(auto, 1fr)",
- },
- {
- key: "classification",
- title: t("schema-editor.column.classification"),
- hide: !supportClassification.value,
- width: "minmax(auto, 2fr)",
- },
- {
- key: "raw-count",
- title: t("schema-editor.database.row-count"),
- width: "minmax(auto, 0.7fr)",
- },
- {
- key: "data-size",
- title: t("schema-editor.database.data-size"),
- width: "minmax(auto, 0.7fr)",
- },
- {
- key: "engine",
- title: t("schema-editor.database.engine"),
- width: "minmax(auto, 1fr)",
- },
- {
- key: "collation",
- title: t("schema-editor.database.collation"),
- width: "minmax(auto, 1fr)",
- },
- {
- key: "comment",
- title: t("schema-editor.database.comment"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: "",
- width: "30px",
- hide: readonly.value,
- },
- ].filter((header) => !header.hide);
-});
-
watch(
[() => currentTab.value, () => schemaList],
() => {
@@ -494,8 +281,16 @@ watch(
}
);
-const isDroppedTable = (table: Table) => {
- return table.status === "dropped";
+const onClassificationSelect = (classificationId: string) => {
+ state.showClassificationDrawer = false;
+ const table = tableList.value.find(
+ (table) => table.id === state.activeTableId
+ );
+ if (!table) {
+ return;
+ }
+ table.classification = classificationId;
+ state.activeTableId = undefined;
};
const handleChangeTab = (tab: SubtabType) => {
@@ -526,22 +321,6 @@ const handleTableItemClick = (table: Table) => {
});
};
-const handleDropTable = (table: Table) => {
- editorStore.dropTable(
- currentTab.value.parentName,
- state.selectedSchemaId,
- table.id
- );
-};
-
-const handleRestoreTable = (table: Table) => {
- editorStore.restoreTable(
- currentTab.value.parentName,
- state.selectedSchemaId,
- table.id
- );
-};
-
const {
databaseMetadata,
schemaStatus,
@@ -594,7 +373,7 @@ const handleApplyTemplate = (template: SchemaTemplateSetting_TableTemplate) => {
state.showFeatureModal = true;
return;
}
- if (!template.table || template.engine !== databaseEngine.value) {
+ if (!template.table || template.engine !== engine.value) {
return;
}
@@ -620,9 +399,3 @@ const handleApplyTemplate = (template: SchemaTemplateSetting_TableTemplate) => {
}
};
</script>
-
-<style scoped>
-.table-item-cell {
- @apply !py-0.5;
-}
-</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList.vue
new file mode 100644
index 0000000000..6eeb1ee461
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList.vue
@@ -0,0 +1,356 @@
+<template>
+ <div class="w-full h-full">
+ <BBGrid
+ class="border"
+ :column-list="tableHeaderList"
+ :data-source="tableList"
+ :custom-header="true"
+ :row-clickable="false"
+ >
+ <template #header>
+ <div role="table-row" class="bb-grid-row bb-grid-header-row group">
+ <div
+ v-for="(header, index) in tableHeaderList"
+ :key="index"
+ role="table-cell"
+ class="bb-grid-header-cell"
+ >
+ {{ header.title }}
+ </div>
+ </div>
+ </template>
+ <template #item="{ item: table, row }: { item: Table, row: number }">
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ <NEllipsis
+ class="w-full cursor-pointer leading-6 my-2 hover:text-accent"
+ >
+ <span @click="handleTableItemClick(table)">
+ {{ table.name }}
+ </span>
+ </NEllipsis>
+ </div>
+ <div
+ v-if="supportClassification"
+ class="bb-grid-cell flex items-center gap-x-2 text-sm"
+ :class="getTableClassList(table, row)"
+ >
+ <ClassificationLevelBadge
+ :classification="table.classification"
+ :classification-config="classificationConfig"
+ />
+ <div v-if="!readonly && !disableChangeTable(table)" class="flex">
+ <button
+ v-if="table.classification"
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="table.classification = ''"
+ >
+ <heroicons-outline:x class="w-3 h-3" />
+ </button>
+ <button
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="showClassificationDrawer(table)"
+ >
+ <heroicons-outline:pencil class="w-3 h-3" />
+ </button>
+ </div>
+ </div>
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ {{ table.rowCount }}
+ </div>
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ {{ bytesToString(table.dataSize) }}
+ </div>
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ {{ table.engine }}
+ </div>
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ {{ table.collation }}
+ </div>
+ <div class="bb-grid-cell" :class="getTableClassList(table, row)">
+ {{ table.userComment }}
+ </div>
+ <div
+ v-if="!readonly"
+ class="bb-grid-cell !px-0.5 flex justify-start items-center"
+ :class="getTableClassList(table, row)"
+ >
+ <NTooltip v-if="!isDroppedTable(table)" trigger="hover" to="body">
+ <template #trigger>
+ <heroicons:trash
+ class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
+ @click="handleDropTable(table)"
+ />
+ </template>
+ <span>{{ $t("schema-editor.actions.drop-table") }}</span>
+ </NTooltip>
+ <NTooltip v-else trigger="hover" to="body">
+ <template #trigger>
+ <heroicons:arrow-uturn-left
+ class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
+ @click="handleRestoreTable(table)"
+ />
+ </template>
+ <span>{{ $t("schema-editor.actions.restore") }}</span>
+ </NTooltip>
+ </div>
+ </template>
+ </BBGrid>
+ </div>
+
+ <TableNameModal
+ v-if="state.tableNameModalContext !== undefined"
+ :parent-name="state.tableNameModalContext.parentName"
+ :schema-id="state.tableNameModalContext.schemaId"
+ :table-name="state.tableNameModalContext.tableName"
+ @close="state.tableNameModalContext = undefined"
+ />
+
+ <Drawer
+ :show="state.showSchemaTemplateDrawer"
+ @close="state.showSchemaTemplateDrawer = false"
+ >
+ <DrawerContent :title="$t('schema-template.table-template.self')">
+ <div class="w-[calc(100vw-36rem)] min-w-[64rem] max-w-[calc(100vw-8rem)]">
+ <TableTemplates
+ :engine="engine"
+ :readonly="true"
+ @apply="handleApplyTemplate"
+ />
+ </div>
+ </DrawerContent>
+ </Drawer>
+
+ <SelectClassificationDrawer
+ v-if="classificationConfig"
+ :show="state.showClassificationDrawer"
+ :classification-config="classificationConfig"
+ @dismiss="state.showClassificationDrawer = false"
+ @select="onClassificationSelect"
+ />
+
+ <FeatureModal
+ feature="bb.feature.schema-template"
+ :open="state.showFeatureModal"
+ @cancel="state.showFeatureModal = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { NEllipsis, NTooltip } from "naive-ui";
+import { computed, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { Drawer, DrawerContent } from "@/components/v2";
+import {
+ hasFeature,
+ generateUniqueTabId,
+ useSettingV1Store,
+ useSchemaEditorV1Store,
+} from "@/store";
+import { SchemaTemplateSetting_TableTemplate } from "@/types/proto/v1/setting_service";
+import {
+ Table,
+ DatabaseTabContext,
+ SchemaEditorTabType,
+ convertTableMetadataToTable,
+} from "@/types/v1/schemaEditor";
+import { bytesToString, isDev } from "@/utils";
+import TableTemplates from "@/views/SchemaTemplate/TableTemplates.vue";
+import TableNameModal from "../Modals/TableNameModal.vue";
+import { isTableChanged } from "../utils";
+
+const props = defineProps<{
+ schemaId: string;
+ tableList: Table[];
+}>();
+
+interface LocalState {
+ showFeatureModal: boolean;
+ showSchemaTemplateDrawer: boolean;
+ showClassificationDrawer: boolean;
+ tableNameModalContext?: {
+ parentName: string;
+ schemaId: string;
+ tableName: string | undefined;
+ };
+ activeTableId?: string;
+}
+
+const { t } = useI18n();
+const editorStore = useSchemaEditorV1Store();
+const settingStore = useSettingV1Store();
+const currentTab = computed(
+ () => (editorStore.currentTab || {}) as DatabaseTabContext
+);
+const state = reactive<LocalState>({
+ showFeatureModal: false,
+ showSchemaTemplateDrawer: false,
+ showClassificationDrawer: false,
+});
+
+const engine = computed(() => {
+ return editorStore.getCurrentEngine(currentTab.value.parentName);
+});
+const readonly = computed(() => editorStore.readonly);
+
+const schemaList = computed(() => {
+ return editorStore.currentSchemaList;
+});
+const tableList = computed(() => {
+ return props.tableList;
+});
+
+const classificationConfig = computed(() => {
+ if (!editorStore.project.dataClassificationConfigId) {
+ return;
+ }
+ return settingStore.getProjectClassification(
+ editorStore.project.dataClassificationConfigId
+ );
+});
+const disableChangeTable = (table: Table): boolean => {
+ return table.status === "dropped";
+};
+
+const getTableClassList = (table: Table, index: number): string[] => {
+ const classList = [];
+ if (table.status === "dropped") {
+ classList.push("text-red-700 !bg-red-50 opacity-70");
+ } else if (table.status === "created") {
+ classList.push("text-green-700 !bg-green-50");
+ } else if (
+ isTableChanged(currentTab.value.parentName, props.schemaId, table.id)
+ ) {
+ classList.push("text-yellow-700 !bg-yellow-50");
+ }
+ if (index % 2 === 1) {
+ classList.push("bg-gray-50");
+ }
+ return classList;
+};
+
+const showClassificationDrawer = (table: Table) => {
+ state.activeTableId = table.id;
+ state.showClassificationDrawer = true;
+};
+
+const onClassificationSelect = (classificationId: string) => {
+ state.showClassificationDrawer = false;
+ const table = tableList.value.find(
+ (table) => table.id === state.activeTableId
+ );
+ if (!table) {
+ return;
+ }
+ table.classification = classificationId;
+ state.activeTableId = undefined;
+};
+
+const supportClassification = computed(() => {
+ return classificationConfig.value && isDev();
+});
+
+const tableHeaderList = computed(() => {
+ return [
+ {
+ key: "name",
+ title: t("schema-editor.database.name"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ key: "classification",
+ title: t("schema-editor.column.classification"),
+ hide: !supportClassification.value,
+ width: "minmax(auto, 1.5fr)",
+ },
+ {
+ key: "raw-count",
+ title: t("schema-editor.database.row-count"),
+ width: "minmax(auto, 0.7fr)",
+ },
+ {
+ key: "data-size",
+ title: t("schema-editor.database.data-size"),
+ width: "minmax(auto, 0.7fr)",
+ },
+ {
+ key: "engine",
+ title: t("schema-editor.database.engine"),
+ width: "minmax(auto, 0.7fr)",
+ },
+ {
+ key: "collation",
+ title: t("schema-editor.database.collation"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ key: "comment",
+ title: t("schema-editor.database.comment"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: "",
+ width: "30px",
+ hide: readonly.value,
+ },
+ ].filter((header) => !header.hide);
+});
+
+const isDroppedTable = (table: Table) => {
+ return table.status === "dropped";
+};
+
+const handleTableItemClick = (table: Table) => {
+ editorStore.addTab({
+ id: generateUniqueTabId(),
+ type: SchemaEditorTabType.TabForTable,
+ parentName: currentTab.value.parentName,
+ schemaId: props.schemaId,
+ tableId: table.id,
+ name: table.name,
+ });
+};
+
+const handleDropTable = (table: Table) => {
+ editorStore.dropTable(currentTab.value.parentName, props.schemaId, table.id);
+};
+
+const handleRestoreTable = (table: Table) => {
+ editorStore.restoreTable(
+ currentTab.value.parentName,
+ props.schemaId,
+ table.id
+ );
+};
+
+const handleApplyTemplate = (template: SchemaTemplateSetting_TableTemplate) => {
+ state.showSchemaTemplateDrawer = false;
+ if (!hasFeature("bb.feature.schema-template")) {
+ state.showFeatureModal = true;
+ return;
+ }
+ if (!template.table || template.engine !== engine.value) {
+ return;
+ }
+
+ const tableEdit = convertTableMetadataToTable(
+ template.table,
+ "created",
+ template.config
+ );
+
+ const selectedSchema = schemaList.value.find(
+ (schema) => schema.id === props.schemaId
+ );
+ if (selectedSchema) {
+ selectedSchema.tableList.push(tableEdit);
+ editorStore.addTab({
+ id: generateUniqueTabId(),
+ type: SchemaEditorTabType.TabForTable,
+ parentName: currentTab.value.parentName,
+ schemaId: props.schemaId,
+ tableId: tableEdit.id,
+ name: template.table.name,
+ });
+ }
+};
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/TabsContainer.vue b/frontend/src/components/SchemaEditorV1/TabsContainer.vue
index e9f75818a0..09ed24b494 100644
--- a/frontend/src/components/SchemaEditorV1/TabsContainer.vue
+++ b/frontend/src/components/SchemaEditorV1/TabsContainer.vue
@@ -1,18 +1,18 @@
<template>
<div class="flex justify-between items-center">
<div
- class="relative flex flex-1 flex-nowrap overflow-hidden overflow bg-gray-100 select-none shrink-0 p-1 rounded"
+ class="relative flex flex-1 flex-nowrap overflow-hidden overflow bg-gray-100 select-none shrink-0 rounded"
>
<div
ref="tabsContainerRef"
- class="flex flex-nowrap overflow-x-auto max-x-full hide-scrollbar overscroll-none"
+ class="flex flex-nowrap overflow-x-auto max-x-full hide-scrollbar overscroll-none px-1 space-x-1"
>
<div
v-for="tab in tabList"
ref="tabsContainerRef"
:key="tab.id"
- class="relative px-1 pl-2 py-1 rounded w-40 flex flex-row justify-between items-center shrink-0 border border-transparent cursor-pointer"
:class="[
+ `relative px-1 py-1 my-1 rounded w-40 flex flex-row justify-between items-center shrink-0 border border-transparent cursor-pointer`,
`tab-${tab.id}`,
tab.id === currentTab?.id && 'bg-white border-gray-200 shadow',
]"
@@ -20,13 +20,17 @@
>
<div class="flex flex-row justify-start items-center mr-1">
<span class="mr-1">
+ <heroicons-outline:circle-stack
+ v-if="tab.type === SchemaEditorTabType.TabForDatabase"
+ class="rounded w-4 h-auto text-gray-400"
+ />
<heroicons-outline:table-cells
v-if="tab.type === SchemaEditorTabType.TabForTable"
class="rounded w-4 h-auto text-gray-400"
/>
</span>
<NEllipsis
- class="text-sm w-24"
+ class="text-sm w-20 leading-4"
:class="getTabComputedClassList(tab)"
>{{ getTabName(tab) }}</NEllipsis
>
@@ -40,24 +44,12 @@
</div>
</div>
</div>
- <div v-if="currentTab" class="hidden lg:block p-1">
- <NInput
- v-if="currentTab.type === SchemaEditorTabType.TabForDatabase"
- v-model:value="searchPattern"
- class="!w-48"
- :placeholder="$t('schema-editor.search-table')"
- @input="$emit('onTableSearchPattern', $event)"
- >
- <template #prefix>
- <heroicons-outline:search class="w-4 h-auto text-gray-300" />
- </template>
- </NInput>
+ <div v-if="currentTab" class="pl-2">
<NInput
- v-if="currentTab.type === SchemaEditorTabType.TabForTable"
v-model:value="searchPattern"
- class="!w-48"
- :placeholder="$t('schema-editor.search-column')"
- @input="$emit('onColumnSearchPattern', $event)"
+ class="!w-40"
+ :placeholder="searchBoxPlaceholder"
+ @input="handleSearchBoxInput"
>
<template #prefix>
<heroicons-outline:search class="w-4 h-auto text-gray-300" />
@@ -68,24 +60,25 @@
</template>
<script lang="ts" setup>
-import { NEllipsis } from "naive-ui";
+import { NEllipsis, NInput } from "naive-ui";
import scrollIntoView from "scroll-into-view-if-needed";
import { computed, nextTick, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
import { useSchemaEditorV1Store } from "@/store";
import { SchemaEditorTabType, TabContext } from "@/types/v1/schemaEditor";
import { isTableChanged } from "./utils";
-defineEmits<{
+const emit = defineEmits<{
(event: "onTableSearchPattern", tableSearchPattern: string): void;
(event: "onColumnSearchPattern", columnSearchPattern: string): void;
}>();
+const { t } = useI18n();
+const schemaEditorV1Store = useSchemaEditorV1Store();
+const tabsContainerRef = ref();
const searchPattern = ref("");
-
const originalTabContext = ref<TabContext | undefined>(undefined);
-const schemaEditorV1Store = useSchemaEditorV1Store();
-const tabsContainerRef = ref();
const tabList = computed(() => {
return schemaEditorV1Store.tabList;
});
@@ -93,6 +86,22 @@ const currentTab = computed(() => {
return schemaEditorV1Store.currentTab;
});
+const searchBoxPlaceholder = computed(() => {
+ return currentTab.value?.type === SchemaEditorTabType.TabForDatabase
+ ? t("schema-editor.search-table")
+ : currentTab.value?.type === SchemaEditorTabType.TabForTable
+ ? t("schema-editor.search-column")
+ : "";
+});
+
+const handleSearchBoxInput = (value: string) => {
+ if (currentTab.value?.type === SchemaEditorTabType.TabForDatabase) {
+ emit("onTableSearchPattern", value);
+ } else if (currentTab.value?.type === SchemaEditorTabType.TabForTable) {
+ emit("onColumnSearchPattern", value);
+ }
+};
+
watch(
() => currentTab.value,
() => {
@@ -139,6 +148,9 @@ const getTabName = (tab: TabContext) => {
return tab.name;
}
if (tab.type === SchemaEditorTabType.TabForDatabase) {
+ if (schemaEditorV1Store.resourceType === "branch") {
+ return "Tables";
+ }
const database = schemaEditorV1Store.databaseList.find(
(database) => database.name === tab.parentName
);
diff --git a/frontend/src/components/SchemaEditorV1/utils/metadata.ts b/frontend/src/components/SchemaEditorV1/utils/metadata.ts
index 13a2125d22..25f9defe38 100644
--- a/frontend/src/components/SchemaEditorV1/utils/metadata.ts
+++ b/frontend/src/components/SchemaEditorV1/utils/metadata.ts
@@ -32,12 +32,10 @@ export const mergeSchemaEditToMetadata = (
(item) => item.name !== schemaEdit.name
);
metadata.schemas.push(transformSchemaEditToMetadata(schemaEdit));
- continue;
} else if (schemaEdit.status === "dropped") {
metadata.schemas = metadata.schemas.filter(
(item) => item.name !== schemaEdit.name
);
- continue;
} else {
const schema = metadata.schemas.find(
(item) => item.name === schemaEdit.name
@@ -46,6 +44,7 @@ export const mergeSchemaEditToMetadata = (
metadata.schemas.push(transformSchemaEditToMetadata(schemaEdit));
continue;
}
+
for (const tableEdit of schemaEdit.tableList) {
if (tableEdit.status === "created") {
// Remove table if it exists.
@@ -53,12 +52,10 @@ export const mergeSchemaEditToMetadata = (
(item) => item.name !== tableEdit.name
);
schema.tables.push(transformTableEditToMetadata(tableEdit));
- continue;
} else if (tableEdit.status === "dropped") {
schema.tables = schema.tables.filter(
(item) => item.name !== tableEdit.name
);
- continue;
} else {
const table = schema.tables.find(
(item) => item.name === tableEdit.name
@@ -67,6 +64,7 @@ export const mergeSchemaEditToMetadata = (
schema.tables.push(transformTableEditToMetadata(tableEdit));
continue;
}
+
for (const columnEdit of tableEdit.columnList) {
if (columnEdit.status === "created") {
// Remove column if it exists.
@@ -109,8 +107,12 @@ export const mergeSchemaEditToMetadata = (
);
}
}
+ table.comment = tableEdit.comment;
+ table.userComment = tableEdit.userComment;
+ table.classification = tableEdit.classification || "";
}
}
+
for (const table of schema.tables) {
const tableEdit = schemaEdit.tableList.find(
(item) => item.name === table.name