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: extract schema editor engine checks (#9805)
Liu Jidb3c8b0a38f4
diff --git a/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vueindex 4e910c058e..338f9803b4 100644--- a/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue+++ b/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue@@ -98,6 +98,7 @@ import SchemaNameModal from "../Modals/SchemaNameModal.vue";import TableNameModal from "../Modals/TableNameModal.vue";import { useSchemaEditorContext } from "../context";import { keyForResource, keyForResourceName } from "../context/common";+import { engineHasSchema } from "../engine-specs";interface BaseTreeNode extends TreeOption {key: string;@@ -552,7 +553,7 @@ const handleShowDropdown = (e: MouseEvent, treeNode: TreeNode) => {};const handleCreateSchemaOrTable = () => {- if (engine.value === Engine.MYSQL || engine.value === Engine.TIDB) {+ if (!engineHasSchema(engine.value)) {const schema = head(schemaList.value);if (schema) {state.tableNameModalContext = {@@ -562,7 +563,7 @@ const handleCreateSchemaOrTable = () => {table: undefined,};}- } else if (engine.value === Engine.POSTGRES) {+ } else {state.schemaNameModalContext = {database: database.value,metadata: metadata.value,diff --git a/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vueindex c2293f3544..b59647fbf7 100644--- a/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue+++ b/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue@@ -97,6 +97,7 @@ import SchemaNameModal from "../Modals/SchemaNameModal.vue";import TableNameModal from "../Modals/TableNameModal.vue";import { useSchemaEditorContext } from "../context";import { keyForResource, keyForResourceName } from "../context/common";+import { engineHasSchema } from "../engine-specs";interface BaseTreeNode extends TreeOption {key: string;@@ -225,16 +226,16 @@ const contextMenuOptions = computed(() => {const { engine } = treeNode.instance;if (treeNode.type === "database") {const options: DropdownOption[] = [];- if (engine === Engine.MYSQL) {- options.push({- key: "create-table",- label: t("schema-editor.actions.create-table"),- });- } else if (engine === Engine.POSTGRES) {+ if (engineHasSchema(engine)) {options.push({key: "create-schema",label: t("schema-editor.actions.create-schema"),});+ } else {+ options.push({+ key: "create-table",+ label: t("schema-editor.actions.create-table"),+ });}return options;} else if (treeNode.type === "schema") {@@ -637,9 +638,9 @@ const handleContextMenuDropdownSelect = async (key: string) => {const treeNode = contextMenu.treeNode;if (!treeNode) return;if (treeNode.type === "database") {+ const engine = treeNode.instance.engine;if (key === "create-table") {- const engine = treeNode.instance.engine;- if (engine === Engine.MYSQL) {+ if (!engineHasSchema(engine)) {const schema = head(treeNode.metadata.database.schemas);if (!schema) {return;@@ -652,11 +653,13 @@ const handleContextMenuDropdownSelect = async (key: string) => {};}} else if (key === "create-schema") {- state.schemaNameModalContext = {- db: treeNode.database,- database: treeNode.metadata.database,- schema: undefined,- };+ if (engineHasSchema(engine)) {+ state.schemaNameModalContext = {+ db: treeNode.database,+ database: treeNode.metadata.database,+ schema: undefined,+ };+ }}} else if (treeNode.type === "schema") {if (key === "create-table") {diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/ForeignKeyCell.vue b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/ForeignKeyCell.vueindex 03111ff520..2f11973068 100644--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/ForeignKeyCell.vue+++ b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/ForeignKeyCell.vue@@ -35,9 +35,9 @@<script lang="ts" setup>import { PenSquareIcon } from "lucide-vue-next";import { computed } from "vue";+import { engineHasSchema } from "@/components/SchemaEditorLite/engine-specs";import { MiniActionButton } from "@/components/v2";import { ComposedDatabase } from "@/types";-import { Engine } from "@/types/proto/v1/common";import {ColumnMetadata,DatabaseMetadata,@@ -90,10 +90,10 @@ const referencedNameForFk = (fk: ForeignKeyMetadata) => {(column) => column.name === fk.referencedColumns[position]);- if (props.db.instanceEntity.engine === Engine.MYSQL) {- return `${referencedTable.name}(${referencedColumn?.name})`;- } else {+ if (engineHasSchema(props.db.instanceEntity.engine)) {return `${referencedSchema.name}.${referencedTable.name}(${referencedColumn?.name})`;+ } else {+ return `${referencedTable.name}(${referencedColumn?.name})`;}};</script>diff --git a/frontend/src/components/SchemaEditorLite/engine-specs.ts b/frontend/src/components/SchemaEditorLite/engine-specs.tsnew file mode 100644index 0000000000..9f58e3e60e--- /dev/null+++ b/frontend/src/components/SchemaEditorLite/engine-specs.ts@@ -0,0 +1,5 @@+import { Engine } from "@/types/proto/v1/common";++export const engineHasSchema = (engine: Engine) => {+ return [Engine.POSTGRES].includes(engine);+};diff --git a/frontend/src/utils/schemaEditor/index.ts b/frontend/src/utils/schemaEditor/index.tsindex 75659450e8..b62ad91251 100644--- a/frontend/src/utils/schemaEditor/index.ts+++ b/frontend/src/utils/schemaEditor/index.ts@@ -8,12 +8,21 @@ export const allowUsingSchemaEditor = (databaseList: Database[]): boolean => {});};+export const engineSupportsSchemaEditor = (engine: Engine) => {+ if ([Engine.MYSQL, Engine.TIDB].includes(engine)) {+ return true;+ }+ if ([Engine.POSTGRES].includes(engine)) {+ return true;+ }+ return false;+};+export const allowUsingSchemaEditorV1 = (databaseList: ComposedDatabase[]): boolean => {- const supported = new Set([Engine.MYSQL, Engine.POSTGRES]);return databaseList.every((db) => {- return supported.has(db.instanceEntity.engine);+ return engineSupportsSchemaEditor(db.instanceEntity.engine);});};