Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: extract alter-schema events (#8343)
Liu Jidd472a3032d4
diff --git a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vueindex a7267e2c62..bddc26478f 100644--- a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue+++ b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue@@ -12,14 +12,12 @@<DatabaseTreekey="sql-editor-database-tree"v-model:search-pattern="searchPattern"- @alter-schema="$emit('alter-schema', $event)"/></NTabPane><NTabPane name="instances" :tab="$t('common.instances')"><DatabaseTreekey="sql-editor-database-tree"v-model:search-pattern="searchPattern"- @alter-schema="$emit('alter-schema', $event)"/></NTabPane></NTabs>@@ -27,7 +25,6 @@<DatabaseTreekey="sql-editor-database-tree"v-model:search-pattern="searchPattern"- @alter-schema="$emit('alter-schema', $event)"/></div></div>@@ -41,13 +38,6 @@ import { ConnectionTreeMode } from "@/types";import { hasWorkspacePermissionV1 } from "@/utils";import DatabaseTree from "./DatabaseTree.vue";-defineEmits<{- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;-}>();-const currentUserV1 = useCurrentUserV1();const connectionTreeStore = useConnectionTreeStore();const searchPattern = ref("");diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex 70c731f5fa..90ee606d5e 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -69,7 +69,7 @@ import {CONNECTION_TREE_DELIMITER,useDBSchemaV1Store,} from "@/store";-import type { ConnectionAtom, CoreTabInfo, DatabaseId } from "@/types";+import type { ConnectionAtom, CoreTabInfo } from "@/types";import {ConnectionTreeMode,ConnectionTreeState,@@ -105,11 +105,7 @@ const props = defineProps<{searchPattern?: string;}>();-const emit = defineEmits<{- (- event: "alter-schema",- params: { databaseId: DatabaseId; schema: string; table: string }- ): void;+defineEmits<{(event: "update:search-pattern", keyword: string): void;}>();@@ -122,7 +118,8 @@ const tabStore = useTabStore();const isLoggedIn = useIsLoggedIn();const currentUserV1 = useCurrentUserV1();const sqlEditorStore = useSQLEditorStore();-const { selectedDatabaseSchemaByDatabaseName } = useSQLEditorContext();+const { selectedDatabaseSchemaByDatabaseName, events: editorEvents } =+ useSQLEditorContext();const mounted = useMounted();const treeRef = ref<InstanceType<typeof NTree>>();@@ -301,8 +298,8 @@ const handleSelect = (key: string) => {}if (key === "alter-schema") {- emit("alter-schema", {- databaseId: option.item.id,+ editorEvents.emit("alter-schema", {+ databaseUID: option.item.id,schema: "",table: "",});diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vueindex 1121ad4e3a..48e0f5451f 100644--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue@@ -53,7 +53,7 @@<NButtonv-if="sqlEditorStore.mode === 'BUNDLED'"type="primary"- @click="gotoAlterSchema"+ @click="gotoCreateIssue">{{ isDDL ? $t("database.edit-schema") : $t("database.change-data") }}</NButton>@@ -102,7 +102,7 @@ const handleClose = () => {emit("close");};-const gotoAlterSchema = () => {+const gotoCreateIssue = () => {const { databaseId } = tabStore.currentTab.connection;if (databaseId === String(UNKNOWN_ID)) {pushNotification({@@ -124,7 +124,7 @@ const gotoAlterSchema = () => {},query: {template: isDDL.value ? DDLIssueTemplate : DMLIssueTemplate,- name: `[${database.name}] ${+ name: `[${database.databaseName}] ${isDDL.value ? "Alter schema" : "Change Data"}`,project: database.projectEntity.uid,diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vueindex 67c3364b4b..b6b7634cc5 100644--- a/frontend/src/views/sql-editor/SQLEditorPage.vue+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue@@ -5,7 +5,7 @@:dbl-click-splitter="false"><Pane v-if="windowWidth >= 800" size="20">- <AsidePanel @alter-schema="handleAlterSchema" />+ <AsidePanel /></Pane><template v-else><teleport to="body">@@ -33,7 +33,7 @@width="80vw"placement="left">- <AsidePanel @alter-schema="handleAlterSchema" />+ <AsidePanel /></NDrawer></teleport></template>@@ -63,7 +63,7 @@v-if="showSecondarySidebar && windowWidth >= 1024":size="25">- <SecondarySidebar @alter-schema="handleAlterSchema" />+ <SecondarySidebar /></Pane></Splitpanes></div>@@ -151,6 +151,7 @@ import { Splitpanes, Pane } from "splitpanes";import { computed, reactive } from "vue";import SchemaEditorModal from "@/components/AlterSchemaPrepForm/SchemaEditorModal.vue";import { Drawer, DrawerContent, InstanceV1Name } from "@/components/v2";+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";import {useCurrentUserV1,useDatabaseV1Store,@@ -197,7 +198,7 @@ const databaseStore = useDatabaseV1Store();const sqlEditorStore = useSQLEditorStore();const currentUserV1 = useCurrentUserV1();// provide context for SQL Editor-provideSQLEditorContext();+const { events: editorEvents } = provideSQLEditorContext();// provide context for sheetsconst { showPanel: showSheetPanel } = provideSheetContext();const { show: showSecondarySidebar } = provideSecondarySidebarContext();@@ -232,40 +233,36 @@ const alterSchemaState = reactive<AlterSchemaState>({databaseIdList: [],});-const handleAlterSchema = async (params: {- databaseId: string;- schema: string;- table: string;-}) => {- const { databaseId, schema, table } = params;- const database = databaseStore.getDatabaseByUID(databaseId);- if (allowUsingSchemaEditorV1([database])) {- // await useProjectV1Store().getOrFetchProjectByUID(- // String(database.projectEntity.uid)- // );- // TODO: support open selected database tab directly in Schema Editor.- alterSchemaState.databaseIdList = [databaseId].map((uid) => Number(uid));- alterSchemaState.showModal = true;- } else {- const exampleSQL = ["ALTER TABLE"];- if (table) {- if (schema) {- exampleSQL.push(`${schema}.${table}`);- } else {- exampleSQL.push(`${table}`);+useEmitteryEventListener(+ editorEvents,+ "alter-schema",+ ({ databaseUID, schema, table }) => {+ const database = databaseStore.getDatabaseByUID(databaseUID);+ if (allowUsingSchemaEditorV1([database])) {+ // TODO: support open selected database tab directly in Schema Editor.+ alterSchemaState.databaseIdList = [databaseUID].map((uid) => Number(uid));+ alterSchemaState.showModal = true;+ } else {+ const exampleSQL = ["ALTER TABLE"];+ if (table) {+ if (schema) {+ exampleSQL.push(`${schema}.${table}`);+ } else {+ exampleSQL.push(`${table}`);+ }}+ const query = {+ template: "bb.issue.database.schema.update",+ name: `[${database.name}] Alter schema`,+ project: database.projectEntity.uid,+ databaseList: databaseUID,+ sql: exampleSQL.join(" "),+ };+ const url = `/issue/new?${stringify(query)}`;+ window.open(url, "_blank");}- const query = {- template: "bb.issue.database.schema.update",- name: `[${database.name}] Alter schema`,- project: database.projectEntity.uid,- databaseList: databaseId,- sql: exampleSQL.join(" "),- };- const url = `/issue/new?${stringify(query)}`;- window.open(url, "_blank");}-};+);</script><style>diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/InfoTabPane.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/InfoTabPane.vueindex 4879f01cb8..d8c56dc04b 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/InfoTabPane.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/InfoTabPane.vue@@ -1,14 +1,7 @@<template>- <SchemaPanel @alter-schema="$emit('alter-schema', $event)" />+ <SchemaPanel /></template><script setup lang="ts">import SchemaPanel from "./SchemaPanel";--defineEmits<{- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;-}>();</script>diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vueindex 524d380510..c0e526f4a4 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue@@ -27,8 +27,8 @@":database="database"@click="- emit('alter-schema', {- databaseId: database.uid,+ editorEvents.emit('alter-schema', {+ databaseUID: database.uid,schema: '',table: '',})@@ -62,6 +62,7 @@ import {instanceV1HasAlterSchema,isTableQueryable,} from "@/utils";+import { useSQLEditorContext } from "@/views/sql-editor/context";import AlterSchemaButton from "./AlterSchemaButton.vue";import ExternalLinkButton from "./ExternalLinkButton.vue";import SchemaDiagramButton from "./SchemaDiagramButton.vue";@@ -76,12 +77,9 @@ const props = defineProps<{const emit = defineEmits<{(e: "click-header"): void;(e: "select-table", schema: SchemaMetadata, table: TableMetadata): void;- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;}>();+const { events: editorEvents } = useSQLEditorContext();const currentUser = useCurrentUserV1();const sqlEditorStore = useSQLEditorStore();diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vueindex 8c2a584925..ef9308fcff 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue@@ -21,7 +21,6 @@:header-clickable="selected !== undefined"@click-header="selected = undefined"@select-table="handleSelectTable"- @alter-schema="emit('alter-schema', $event)"/><Transition name="slide-up"><TableSchema@@ -32,7 +31,6 @@:schema="selected.schema":table="selected.table"@close="selected = undefined"- @alter-schema="emit('alter-schema', $event)"/></Transition></template>@@ -61,13 +59,6 @@ import DatabaseSchema from "./DatabaseSchema.vue";import TableSchema from "./TableSchema.vue";import { provideSchemaPanelContext } from "./context";-const emit = defineEmits<{- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;-}>();-const { selectedDatabaseSchemaByDatabaseName } = useSQLEditorContext();const dbSchemaStore = useDBSchemaV1Store();diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vueindex 53407a9a21..48bf83aef6 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue@@ -23,8 +23,8 @@:schema="schema":table="table"@click="- emit('alter-schema', {- databaseId: database.uid,+ editorEvents.emit('alter-schema', {+ databaseUID: database.uid,schema: schema.name,table: table.name,})@@ -48,6 +48,7 @@ import type {TableMetadata,} from "@/types/proto/v1/database_service";import { databaseV1Slug } from "@/utils";+import { useSQLEditorContext } from "@/views/sql-editor/context";import AlterSchemaButton from "./AlterSchemaButton.vue";import ColumnList from "./ColumnList.vue";import ExternalLinkButton from "./ExternalLinkButton.vue";@@ -61,12 +62,9 @@ const props = defineProps<{const emit = defineEmits<{(e: "close"): void;- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;}>();+const { events: editorEvents } = useSQLEditorContext();const sqlEditorStore = useSQLEditorStore();const tableDetailLink = computed((): string => {diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue b/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vueindex 21ff6a31c6..3dcd4b66f5 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue@@ -1,9 +1,6 @@<template><div class="h-full">- <InfoTabPane- v-if="tab === 'INFO'"- @alter-schema="$emit('alter-schema', $event)"- />+ <InfoTabPane v-if="tab === 'INFO'" /><SheetTabPane v-if="tab === 'SHEET'" /><HistoryTabPane v-if="tab === 'HISTORY'" /></div>@@ -15,12 +12,5 @@ import InfoTabPane from "./InfoTabPane";import SheetTabPane from "./SheetTabPane";import { useSecondarySidebarContext } from "./context";-defineEmits<{- (- event: "alter-schema",- params: { databaseId: string; schema: string; table: string }- ): void;-}>();-const { tab } = useSecondarySidebarContext();</script>diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.tsindex e08ee83d70..8fea79bd29 100644--- a/frontend/src/views/sql-editor/context.ts+++ b/frontend/src/views/sql-editor/context.ts@@ -9,6 +9,11 @@ import {type SQLEditorEvents = Emittery<{"save-sheet": { title: string };+ "alter-schema": {+ databaseUID: string;+ schema: string;+ table: string;+ };}>;export type SelectedDatabaseSchema = {