Skip to content

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

chore: update schema editor v1 state definition (#8195)

boojackbd6ee896de3d
diff --git a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
index cd4c8f4eee..0d225c9fe3 100644
--- a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
@@ -48,14 +48,12 @@
@update="handleBaselineSchemaChange"
/>
<SchemaEditorV1
- ref="schemaEditorRef"
:key="refreshId"
class="!mt-6"
- :readonly="true"
- :engine="state.schemaDesign.engine"
:project="project"
:resource-type="'branch'"
:branches="[state.schemaDesign]"
+ :readonly="true"
/>
</div>
@@ -138,7 +136,6 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-const schemaEditorRef = ref<InstanceType<typeof SchemaEditorV1>>();
const projectStore = useProjectV1Store();
const databaseStore = useDatabaseV1Store();
const schemaDesignStore = useSchemaDesignStore();
@@ -230,11 +227,6 @@ const handleConfirm = async () => {
return;
}
- const designerState = schemaEditorRef.value;
- if (!designerState) {
- // Should not happen.
- throw new Error("schema designer is undefined");
- }
if (!validateBranchName(state.schemaDesignTitle)) {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
index 53a2ab0ea2..dec4a3184d 100644
--- a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
@@ -149,9 +149,7 @@
<SchemaEditorV1
:key="schemaEditorKey"
- ref="schemaEditorRef"
:readonly="!state.isEditing"
- :engine="schemaDesign.engine"
:project="project"
:resource-type="'branch'"
:branches="[schemaDesign]"
@@ -262,7 +260,6 @@ const state = reactive<LocalState>({
showDiffEditor: false,
});
const createdBranchName = ref<string>("");
-const schemaEditorRef = ref<InstanceType<typeof SchemaEditorV1>>();
const schemaEditorKey = ref<string>(uniqueId());
const schemaDesign = computed(() => {
@@ -488,10 +485,6 @@ const handleSaveSchemaDesignDraft = async () => {
return;
}
- const designerState = schemaEditorRef.value;
- if (!designerState) {
- throw new Error("schema designer is undefined");
- }
if (state.schemaDesignTitle === "") {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
index ce7adc3bd6..58618cf625 100644
--- a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
+++ b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
@@ -78,6 +78,7 @@ import SchemaIcon from "~icons/heroicons-outline/view-columns";
import EllipsisIcon from "~icons/heroicons-solid/ellipsis-horizontal";
import { generateUniqueTabId, useSchemaEditorV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
+import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
import { Table } from "@/types/v1/schemaEditor";
import { BranchSchema, SchemaEditorTabType } from "@/types/v1/schemaEditor";
import { getHighlightHTMLByKeyWords, isDescendantOf } from "@/utils";
@@ -129,7 +130,6 @@ const schemaEditorV1Store = useSchemaEditorV1Store();
const state = reactive<LocalState>({
shouldRelocateTreeNode: false,
});
-const engine = computed(() => schemaEditorV1Store.engine);
const readonly = computed(() => schemaEditorV1Store.readonly);
const currentTab = computed(() => schemaEditorV1Store.currentTab);
@@ -153,6 +153,9 @@ const branchSchema = computed(
Array.from(schemaEditorV1Store.resourceMap.branch.values())
) as BranchSchema
);
+const engine = computed(() => {
+ return (branchSchema.value.branch as any as SchemaDesign).engine;
+});
const schemaList = computed(() => branchSchema.value.schemaList);
const tableList = computed(() =>
diff --git a/frontend/src/components/SchemaEditorV1/Modals/EditColumnForeignKeyModal.vue b/frontend/src/components/SchemaEditorV1/Modals/EditColumnForeignKeyModal.vue
index d6f5513552..550bb0ee93 100644
--- a/frontend/src/components/SchemaEditorV1/Modals/EditColumnForeignKeyModal.vue
+++ b/frontend/src/components/SchemaEditorV1/Modals/EditColumnForeignKeyModal.vue
@@ -76,8 +76,9 @@ import { isUndefined } from "lodash-es";
import { computed, onMounted, reactive, watch } from "vue";
import { BBModal, BBSelect } from "@/bbkit";
import { useSchemaEditorV1Store } from "@/store";
-import { Column, ForeignKey } from "@/types";
+import { Column, ComposedDatabase, ForeignKey } from "@/types";
import { Engine } from "@/types/proto/v1/common";
+import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
interface LocalState {
referencedSchemaId?: string;
@@ -101,7 +102,21 @@ const state = reactive<LocalState>({
referencedSchemaId: props.schemaId,
});
-const engine = computed(() => schemaEditorV1Store.engine);
+const parentResouce = computed(() => {
+ return schemaEditorV1Store.resourceMap[schemaEditorV1Store.resourceType].get(
+ props.parentName
+ )!;
+});
+const engine = computed(() => {
+ if (schemaEditorV1Store.resourceType === "branch") {
+ return (parentResouce.value as any as SchemaDesign).engine;
+ } else if (schemaEditorV1Store.resourceType === "database") {
+ return (parentResouce.value as any as ComposedDatabase).instanceEntity
+ .engine;
+ } else {
+ return Engine.MYSQL;
+ }
+});
const parentResource = computed(() => {
return schemaEditorV1Store.resourceMap[schemaEditorV1Store.resourceType].get(
diff --git a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
index 20fcf93edf..ad76dea4eb 100644
--- a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
+++ b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
@@ -37,11 +37,13 @@ import {
useNotificationStore,
useSchemaEditorV1Store,
} from "@/store";
+import { ComposedDatabase } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import {
ColumnMetadata,
TableMetadata,
} from "@/types/proto/v1/database_service";
+import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
import {
SchemaEditorTabType,
convertColumnMetadataToColumn,
@@ -71,7 +73,21 @@ const state = reactive<LocalState>({
tableName: "",
});
-const engine = computed(() => schemaEditorV1Store.engine);
+const parentResouce = computed(() => {
+ return schemaEditorV1Store.resourceMap[schemaEditorV1Store.resourceType].get(
+ props.parentName
+ )!;
+});
+const engine = computed(() => {
+ if (schemaEditorV1Store.resourceType === "branch") {
+ return (parentResouce.value as any as SchemaDesign).engine;
+ } else if (schemaEditorV1Store.resourceType === "database") {
+ return (parentResouce.value as any as ComposedDatabase).instanceEntity
+ .engine;
+ } else {
+ return Engine.MYSQL;
+ }
+});
const isCreatingTable = computed(() => {
return props.tableId === undefined;
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
index 234a97ce31..c3926d248a 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
@@ -82,6 +82,7 @@
class="table-body-item-container flex items-center gap-x-2 ml-3 text-sm"
>
<ClassificationLevelBadge
+ v-if="column.classification && classificationConfig"
:classification="column.classification"
:classification-config="classificationConfig"
/>
@@ -291,8 +292,10 @@ import {
useSettingV1Store,
useSchemaEditorV1Store,
} from "@/store/modules";
+import { ComposedDatabase } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { ColumnMetadata } from "@/types/proto/v1/database_service";
+import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
import { SchemaTemplateSetting_FieldTemplate } from "@/types/proto/v1/setting_service";
import {
Column,
@@ -326,7 +329,16 @@ const parentResouce = computed(() => {
currentTab.value.parentName
)!;
});
-const engine = computed(() => schemaEditorV1Store.engine);
+const engine = computed(() => {
+ if (schemaEditorV1Store.resourceType === "branch") {
+ return (parentResouce.value as any as SchemaDesign).engine;
+ } else if (schemaEditorV1Store.resourceType === "database") {
+ return (parentResouce.value as any as ComposedDatabase).instanceEntity
+ .engine;
+ } else {
+ return Engine.MYSQL;
+ }
+});
const readonly = computed(() => schemaEditorV1Store.readonly);
const project = computed(() => schemaEditorV1Store.project);
const state = reactive<LocalState>({
diff --git a/frontend/src/components/SchemaEditorV1/index.vue b/frontend/src/components/SchemaEditorV1/index.vue
index c30d9b15d5..f01253e295 100644
--- a/frontend/src/components/SchemaEditorV1/index.vue
+++ b/frontend/src/components/SchemaEditorV1/index.vue
@@ -18,20 +18,15 @@ import { Splitpanes, Pane } from "splitpanes";
import { onMounted, watch, reactive } from "vue";
import { useSchemaEditorV1Store, useSettingV1Store } from "@/store";
import { ComposedProject, ComposedDatabase } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
-import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
import Aside from "./Aside/index.vue";
import Editor from "./Editor.vue";
import { convertBranchToBranchSchema } from "./utils/branch";
const props = defineProps<{
- readonly: boolean;
- engine: Engine;
project: ComposedProject;
- baselineSchemaMetadata?: DatabaseMetadata;
- schemaMetadata?: DatabaseMetadata;
resourceType: "database" | "branch";
+ readonly?: boolean;
databases?: ComposedDatabase[];
// NOTE: we only support editing one branch for now.
branches?: SchemaDesign[];
@@ -50,14 +45,13 @@ const state = reactive<LocalState>({
const updateSchemaEditorState = () => {
schemaEditorV1Store.setState({
- engine: props.engine,
project: props.project,
- readonly: props.readonly,
resourceType: props.resourceType,
// NOTE: this will clear all tabs. We will restore tabs as needed later.
tabState: {
tabMap: new Map(),
},
+ readonly: props.readonly || false,
});
if (props.resourceType === "database") {
diff --git a/frontend/src/store/modules/v1/schemaEditor.ts b/frontend/src/store/modules/v1/schemaEditor.ts
index 0bcc74dcf3..60a7c888c1 100644
--- a/frontend/src/store/modules/v1/schemaEditor.ts
+++ b/frontend/src/store/modules/v1/schemaEditor.ts
@@ -1,7 +1,6 @@
import { isUndefined, uniqueId } from "lodash-es";
import { defineStore } from "pinia";
import { ComposedDatabase, emptyProject } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
import {
SchemaEditorV1State,
Table,
@@ -16,7 +15,6 @@ export const generateUniqueTabId = () => {
const getDefaultSchemaEditorState = (): SchemaEditorV1State => {
return {
- engine: Engine.MYSQL,
project: emptyProject(),
readonly: false,
resourceType: "database",
diff --git a/frontend/src/types/v1/schemaEditor/state.ts b/frontend/src/types/v1/schemaEditor/state.ts
index ebbfd067b6..10c5cb834c 100644
--- a/frontend/src/types/v1/schemaEditor/state.ts
+++ b/frontend/src/types/v1/schemaEditor/state.ts
@@ -1,5 +1,4 @@
import { ComposedDatabase, ComposedProject } from "..";
-import { Engine } from "../../proto/v1/common";
import { SchemaDesign } from "../../proto/v1/schema_design_service";
import { Schema } from "./atomType";
@@ -42,7 +41,6 @@ export interface BranchSchema {
}
export interface SchemaEditorV1State {
- engine: Engine;
project: ComposedProject;
readonly: boolean;
resourceType: "database" | "branch";