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: remove table store in frontend (#3914)
boojackf374feef8e9f
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vueindex ddb3cd8039..1ae0e14951 100644--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue@@ -184,14 +184,22 @@ import { useI18n } from "vue-i18n";import {pushNotification,+ useDBSchemaStore,useRepositoryStore,- useTableStore,useUIStateStore,} from "@/store";import { useIssueLogic } from "./logic";import MonacoEditor from "../MonacoEditor/MonacoEditor.vue";-import type { Issue, Repository, SQLDialect, Task, TaskId } from "@/types";+import type {+ Database,+ Issue,+ Repository,+ SQLDialect,+ Task,+ TaskId,+} from "@/types";import { baseDirectoryWebUrl, UNKNOWN_ID } from "@/types";+import { TableMetadata } from "@/types/proto/database";import IssueRollbackButton from "./IssueRollbackButton.vue";interface LocalState {@@ -232,8 +240,9 @@ export default defineComponent({applyStatementToOtherTasks,} = useIssueLogic();- const uiStateStore = useUIStateStore();const { t } = useI18n();+ const uiStateStore = useUIStateStore();+ const dbSchemaStore = useDBSchemaStore();const state = reactive<LocalState>({editing: false,@@ -283,20 +292,24 @@ export default defineComponent({state.editStatement = cur;});- const handleMonacoEditorReady = () => {- editorRef.value?.setEditorAutoCompletionContext(- databaseList.value,- tableList.value- );+ const handleUpdateEditorAutoCompletionContext = async () => {+ const databaseMap: Map<Database, TableMetadata[]> = new Map();+ for (const database of databaseList.value) {+ const tableList = await dbSchemaStore.getOrFetchTableListByDatabaseId(+ database.id+ );+ databaseMap.set(database, tableList);+ }+ editorRef.value?.setEditorAutoCompletionContext(databaseMap);+ };+ const handleMonacoEditorReady = () => {+ handleUpdateEditorAutoCompletionContext();updateEditorHeight();};watch([databaseList, tableList], () => {- editorRef.value?.setEditorAutoCompletionContext(- databaseList.value,- tableList.value- );+ handleUpdateEditorAutoCompletionContext();});const updateEditorHeight = () => {@@ -455,7 +468,7 @@ export default defineComponent({const useDatabaseAndTableList = () => {const { selectedDatabase } = useIssueLogic();- const tableStore = useTableStore();+ const dbSchemaStore = useDBSchemaStore();const databaseList = computed(() => {if (selectedDatabase.value) return [selectedDatabase.value];@@ -465,14 +478,14 @@ const useDatabaseAndTableList = () => {watch(databaseList,(list) => {- list.forEach((db) => tableStore.getOrFetchTableListByDatabaseId(db.id));+ list.forEach((db) => dbSchemaStore.getOrFetchDatabaseMetadataById(db.id));},{ immediate: true });const tableList = computed(() => {return databaseList.value- .map((item) => tableStore.getTableListByDatabaseId(item.id))+ .map((item) => dbSchemaStore.getTableListByDatabaseId(item.id)).flat();});diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vueindex 251634a56f..323558cdc4 100644--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue@@ -18,7 +18,8 @@ import {onBeforeUnmount,} from "vue";import type { editor as Editor } from "monaco-editor";-import { Database, SQLDialect, Table } from "@/types";+import { Database, SQLDialect } from "@/types";+import { TableMetadata } from "@/types/proto/database";import { MonacoHelper, useMonaco } from "./useMonaco";import { useLineDecorations } from "./lineDecorations";import type { useLanguageClient } from "@sql-lsp/client";@@ -282,22 +283,23 @@ const formatEditorContent = () => {};const setEditorAutoCompletionContext = (- databases: Database[],- tables: Table[]+ databaseMap: Map<Database, TableMetadata[]>) => {- languageClientRef.value?.changeSchema({- databases: databases.map((db) => ({- name: db.name,- tables: tables- .filter((table) => table.database.id === db.id)- .map((table) => ({- database: db.name,- name: table.name,- columns: table.columnList.map((col) => ({- name: col.name,- })),+ const databases = [];+ for (const [database, tableList] of databaseMap) {+ databases.push({+ name: database.name,+ tables: tableList.map((table) => ({+ database: database.name,+ name: table.name,+ columns: table.columns.map((column) => ({+ name: column.name,})),- })),+ })),+ });+ }+ languageClientRef.value?.changeSchema({+ databases: databases,});};diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 08886f2a01..808738284b 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -24,7 +24,6 @@ import {hasWorkspacePermission,idFromSlug,} from "../utils";-// import PasswordReset from "../views/auth/PasswordReset.vue";import Signin from "../views/auth/Signin.vue";import Signup from "../views/auth/Signup.vue";import DashboardSidebar from "../views/DashboardSidebar.vue";@@ -36,7 +35,6 @@ import {useDataSourceStore,useSQLReviewStore,useProjectStore,- useTableStore,useSheetStore,useAuthStore,useDatabaseStore,@@ -1157,7 +1155,6 @@ router.beforeEach((to, from, next) => {const issueSlug = routerSlug.issueSlug;const instanceSlug = routerSlug.instanceSlug;const databaseSlug = routerSlug.databaseSlug;- const tableName = routerSlug.tableName;const dataSourceSlug = routerSlug.dataSourceSlug;const migrationHistorySlug = routerSlug.migrationHistorySlug;const vcsSlug = routerSlug.vcsSlug;@@ -1300,24 +1297,8 @@ router.beforeEach((to, from, next) => {.fetchDatabaseById(idFromSlug(databaseSlug)).then((database: Database) => {dbSchemaStore.getOrFetchDatabaseMetadataById(database.id).then(() => {- if (!tableName && !dataSourceSlug && !migrationHistorySlug) {+ if (!dataSourceSlug && !migrationHistorySlug) {next();- } else if (tableName) {- useTableStore()- .fetchTableByDatabaseIdAndTableName({- databaseId: database.id,- tableName,- })- .then(() => {- next();- })- .catch((error) => {- next({- name: "error.404",- replace: false,- });- throw error;- });} else if (dataSourceSlug) {useDataSourceStore().fetchDataSourceById({diff --git a/frontend/src/store/modules/connectionTree.ts b/frontend/src/store/modules/connectionTree.tsindex c7b4eb8d49..ded75c9da3 100644--- a/frontend/src/store/modules/connectionTree.ts+++ b/frontend/src/store/modules/connectionTree.ts@@ -1,4 +1,5 @@import { defineStore } from "pinia";+import { reactive, ref } from "vue";import {DatabaseId,InstanceId,@@ -6,12 +7,11 @@ import {Policy,ConnectionAtom,} from "@/types";-import { ConnectionTreeState, UNKNOWN_ID, unknown } from "@/types";+import { ConnectionTreeState, UNKNOWN_ID } from "@/types";import { useDatabaseStore } from "./database";import { useInstanceStore } from "./instance";-import { useTableStore } from "./table";import { emptyConnection } from "@/utils";-import { reactive, ref } from "vue";+import { useDBSchemaStore } from "./dbSchema";export const useConnectionTreeStore = defineStore("connectionTree", () => {// states@@ -21,7 +21,7 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {state: ConnectionTreeState.UNSET,});const expandedTreeNodeKeys = ref<string[]>([]);- const selectedTable = unknown("TABLE");+ const selectedTableAtom = ref<ConnectionAtom>();// actionsconst fetchConnectionByInstanceIdAndDatabaseId = async (@@ -32,7 +32,7 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {await Promise.all([useDatabaseStore().getOrFetchDatabaseById(databaseId),useInstanceStore().getOrFetchInstanceById(instanceId),- useTableStore().getOrFetchTableListByDatabaseId(databaseId),+ useDBSchemaStore().getOrFetchTableListByDatabaseId(databaseId),]);return {@@ -52,10 +52,10 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {useDatabaseStore().getDatabaseListByInstanceId(instanceId),useInstanceStore().getOrFetchInstanceById(instanceId),]);- const tableStore = useTableStore();+ const dbSchemaStore = useDBSchemaStore();await Promise.all(databaseList.map((db) =>- tableStore.getOrFetchTableListByDatabaseId(db.id)+ dbSchemaStore.getOrFetchTableListByDatabaseId(db.id)));@@ -73,7 +73,7 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {accessControlPolicyList,tree,expandedTreeNodeKeys,- selectedTable,+ selectedTableAtom,fetchConnectionByInstanceIdAndDatabaseId,fetchConnectionByInstanceId,};diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex 90e6aea3ea..2cba98b7e3 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -36,7 +36,6 @@ export * from "./webTerminal";export * from "./connectionTree";export * from "./subscription";export * from "./tab";-export * from "./table";export * from "./task";export * from "./uistate";export * from "./vcs";diff --git a/frontend/src/store/modules/schemaEditor.ts b/frontend/src/store/modules/schemaEditor.tsindex 03b32d8955..fbc4fa43fd 100644--- a/frontend/src/store/modules/schemaEditor.ts+++ b/frontend/src/store/modules/schemaEditor.ts@@ -11,7 +11,7 @@ import {DatabaseEdit,ResourceObject,} from "@/types";-import { DatabaseEditResult, DatabaseState } from "@/types/schemaEditor";+import { DatabaseEditResult } from "@/types/schemaEditor";import { Table } from "@/types/schemaEditor/atomType";import { useDatabaseStore, useDBSchemaStore } from ".";import { transformTableDataToTable } from "@/utils/schemaEditor/transform";@@ -26,7 +26,7 @@ const getDefaultSchemaEditorState = (): SchemaEditorState => {tabMap: new Map<string, TabContext>(),currentTabId: "",},- databaseStateById: new Map<DatabaseId, DatabaseState>(),+ databaseStateById: new Map(),};};@@ -177,8 +177,7 @@ export const useSchemaEditorStore = defineStore("SchemaEditor", {});}- return (this.databaseStateById.get(databaseId) as DatabaseState)- .tableList;+ return this.databaseStateById.get(databaseId)!.tableList;},getTableWithTableTab(tab: TableTabContext) {return this.databaseStateById@@ -188,9 +187,7 @@ export const useSchemaEditorStore = defineStore("SchemaEditor", {dropTable(databaseId: DatabaseId, table: Table) {// Remove table record and close tab for created table.if (table.status === "created") {- const tableList = (- this.databaseStateById.get(databaseId) as DatabaseState- ).tableList;+ const tableList = this.databaseStateById.get(databaseId)!.tableList;const index = tableList.findIndex((item) => item.newName === table.newName);diff --git a/frontend/src/store/modules/table.ts b/frontend/src/store/modules/table.tsdeleted file mode 100644index 7c28467fcb..0000000000--- a/frontend/src/store/modules/table.ts+++ /dev/null@@ -1,163 +0,0 @@-import { defineStore } from "pinia";-import axios from "axios";-import {- Column,- Database,- DatabaseId,- ResourceIdentifier,- ResourceObject,- Table,- TableId,- TableIndex,- TableState,- unknown,-} from "@/types";-import { getPrincipalFromIncludedList } from "./principal";-import { useDatabaseStore } from "./database";--function convert(table: ResourceObject, includedList: ResourceObject[]): Table {- const databaseId = (table.relationships!.database.data as ResourceIdentifier)- .id;-- let database: Database = unknown("DATABASE") as Database;- const databaseStore = useDatabaseStore();- for (const item of includedList || []) {- if (item.type == "database" && item.id == databaseId) {- database = databaseStore.convert(item, includedList);- break;- }- }-- const columnList = (table.attributes.columnList as Column[]) || [];- const indexList = (table.attributes.indexList as TableIndex[]) || [];-- return {- ...(table.attributes as Omit<- Table,- "id" | "database" | "creator" | "updater" | "columnList" | "indexList"- >),- id: parseInt(table.id),- creator: getPrincipalFromIncludedList(- table.relationships!.creator.data,- includedList- ),- updater: getPrincipalFromIncludedList(- table.relationships!.updater.data,- includedList- ),- columnList,- indexList,- database,- };-}--export const useTableStore = defineStore("table", {- state: (): TableState => ({- tableListByDatabaseId: new Map(),- }),-- actions: {- getTableListByDatabaseIdAndTableName(- databaseId: DatabaseId,- tableName: string- ): Table | undefined {- const list = this.tableListByDatabaseId.get(databaseId);- if (list) {- return list.find((item: Table) => item.name == tableName);- }- return undefined;- },-- getTableListByDatabaseId(databaseId: DatabaseId): Table[] {- return this.tableListByDatabaseId.get(databaseId) || [];- },-- getTableByDatabaseIdAndTableId(- databaseId: DatabaseId,- tableId: TableId- ): Table {- const list = this.getTableListByDatabaseId(databaseId);- const table = list.find((t) => t.id === tableId);- return table || unknown("TABLE");- },-- async getOrFetchTableByDatabaseIdAndTableId(- databaseId: DatabaseId,- tableId: TableId- ) {- const tableList = await this.getOrFetchTableListByDatabaseId(databaseId);- const table = tableList.find((t) => t.id === tableId);- return table || unknown("TABLE");- },-- setTableByDatabaseIdAndTableName({- databaseId,- tableName,- table,- }: {- databaseId: DatabaseId;- tableName: string;- table: Table;- }) {- const list = this.tableListByDatabaseId.get(databaseId);- if (list) {- const i = list.findIndex((item: Table) => item.name == tableName);- if (i != -1) {- list[i] = table;- } else {- list.push(table);- }- } else {- this.tableListByDatabaseId.set(databaseId, [table]);- }- },-- setTableListByDatabaseId({- databaseId,- tableList,- }: {- databaseId: DatabaseId;- tableList: Table[];- }) {- this.tableListByDatabaseId.set(databaseId, tableList);- },-- async fetchTableByDatabaseIdAndTableName({- databaseId,- tableName,- }: {- databaseId: DatabaseId;- tableName: string;- }) {- const data = (- await axios.get(`/api/database/${databaseId}/table/${tableName}`)- ).data;- const table = convert(data.data, data.included);-- this.setTableByDatabaseIdAndTableName({- databaseId,- tableName,- table,- });- return table;- },-- async fetchTableListByDatabaseId(databaseId: DatabaseId) {- const data = (await axios.get(`/api/database/${databaseId}/table`)).data;- const tableList: Table[] = data.data.map((table: ResourceObject) => {- return convert(table, data.included);- });-- this.setTableListByDatabaseId({ databaseId, tableList });- return tableList;- },-- async getOrFetchTableListByDatabaseId(databaseId: DatabaseId) {- const storedList = this.tableListByDatabaseId.get(databaseId);- if (storedList) {- return storedList;- }- return this.fetchTableListByDatabaseId(databaseId);- },- },-});diff --git a/frontend/src/types/column.ts b/frontend/src/types/column.tsindex 6ebe90bc9b..56387c944f 100644--- a/frontend/src/types/column.ts+++ b/frontend/src/types/column.ts@@ -1,12 +1,13 @@-import { ColumnId, DatabaseId, TableId } from "./id";+import { ColumnId, DatabaseId, IdType } from "./id";+// TODO(steven): remove it.// Columnexport type Column = {id: ColumnId;// Related fieldsdatabaseId: DatabaseId;- tableId: TableId;+ tableId: IdType;// Standard fieldscreatorId: number;diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 7d661226ac..15c83dc0b5 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -26,7 +26,6 @@ import { DeploymentConfig } from "./deployment";import { Policy, DefaultApprovalPolicy } from "./policy";import { Sheet } from "./sheet";import { SQLReviewPolicy } from "./sqlReview";-import { Table } from "./table";import { Column } from "./column";// System bot id@@ -161,7 +160,6 @@ interface ResourceMaker {(type: "DEPLOYMENT_CONFIG"): DeploymentConfig;(type: "SHEET"): Sheet;(type: "SQL_REVIEW"): SQLReviewPolicy;- (type: "TABLE"): Table;(type: "COLUMN"): Column;}@@ -522,31 +520,11 @@ const makeUnknown = (type: ResourceType) => {ruleList: [],};- const UNKNOWN_TABLE: Table = {- id: UNKNOWN_ID,- database: UNKNOWN_DATABASE,- creator: UNKNOWN_PRINCIPAL,- updater: UNKNOWN_PRINCIPAL,- createdTs: 0,- updatedTs: 0,- name: "<<Unknown table>>",- type: "BASE TABLE",- engine: "InnoDB",- collation: "",- rowCount: 0,- dataSize: 0,- indexList: [],- indexSize: 0,- dataFree: 0,- createOptions: "",- comment: "",- columnList: [],- };-+ // TODO(steven): remove UNKNOWN_COLUMNconst UNKNOWN_COLUMN: Column = {id: UNKNOWN_ID,databaseId: UNKNOWN_DATABASE.id,- tableId: UNKNOWN_TABLE.id,+ tableId: UNKNOWN_ID,creatorId: UNKNOWN_PRINCIPAL.id,createdTs: 0,updaterId: UNKNOWN_PRINCIPAL.id,@@ -611,8 +589,6 @@ const makeUnknown = (type: ResourceType) => {return UNKNOWN_SHEET;case "SQL_REVIEW":return UNKNOWN_SQL_REVIEW_POLICY;- case "TABLE":- return UNKNOWN_TABLE;case "COLUMN":return UNKNOWN_COLUMN;}@@ -974,27 +950,6 @@ const makeEmpty = (type: ResourceType) => {ruleList: [],};- const EMPTY_TABLE: Table = {- id: EMPTY_ID,- database: EMPTY_DATABASE,- creator: EMPTY_PRINCIPAL,- updater: EMPTY_PRINCIPAL,- createdTs: 0,- updatedTs: 0,- name: "",- type: "BASE TABLE",- engine: "InnoDB",- collation: "",- rowCount: 0,- dataSize: 0,- indexList: [],- indexSize: 0,- dataFree: 0,- createOptions: "",- comment: "",- columnList: [],- };-switch (type) {case "PRINCIPAL":return EMPTY_PRINCIPAL;diff --git a/frontend/src/types/connectionTree.ts b/frontend/src/types/connectionTree.tsindex d103c86cbe..17ade46aac 100644--- a/frontend/src/types/connectionTree.ts+++ b/frontend/src/types/connectionTree.ts@@ -1,4 +1,4 @@-import { InstanceId, DatabaseId, TableId, ViewId } from "../types";+import { InstanceId, DatabaseId, ViewId } from "../types";export type ConnectionAtomType = "instance" | "database" | "table" | "view";@@ -9,8 +9,8 @@ export enum ConnectionTreeState {}export interface ConnectionAtom {- parentId: InstanceId | DatabaseId | TableId | ViewId;- id: InstanceId | DatabaseId | TableId | ViewId;+ parentId: InstanceId | DatabaseId | ViewId;+ id: InstanceId | DatabaseId | ViewId;key: string;label: string;type?: ConnectionAtomType;diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.tsindex 70ed2e2262..256cf01652 100644--- a/frontend/src/types/id.ts+++ b/frontend/src/types/id.ts@@ -45,8 +45,6 @@ export type DataSourceId = IdType;export type DatabaseId = IdType;-export type TableId = IdType;-export type ViewId = IdType;export type DBExtensionId = IdType;diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 9495f5bd94..425fbb15f5 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -34,7 +34,6 @@ export * from "./repository";export * from "./sql";export * from "./sqlAdvice";export * from "./store";-export * from "./table";export * from "./tableIndex";export * from "./vcs";export * from "./view";diff --git a/frontend/src/types/schemaEditor/index.ts b/frontend/src/types/schemaEditor/index.tsindex 654bbb5aa4..58186dc1f5 100644--- a/frontend/src/types/schemaEditor/index.ts+++ b/frontend/src/types/schemaEditor/index.ts@@ -25,7 +25,7 @@ export type TabContext = DatabaseTabContext | TableTabContext;type TabId = string;-export interface DatabaseState {+interface DatabaseState {database: Database;originTableList: Table[];tableList: Table[];diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 91e58de8b9..5cb3d03e3d 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -45,7 +45,6 @@ import { Project } from "./project";import { ProjectWebhook } from "./projectWebhook";import { Repository } from "./repository";import { Setting, SettingName } from "./setting";-import { Table } from "./table";import { VCS } from "./vcs";import { Label } from "./label";import { ReleaseInfo } from "./actuator";@@ -160,10 +159,6 @@ export interface DBSchemaState {databaseMetadataById: Map<DatabaseId, DatabaseMetadata>;}-export interface TableState {- tableListByDatabaseId: Map<DatabaseId, Table[]>;-}-export interface ViewState {viewListByDatabaseId: Map<DatabaseId, View[]>;}diff --git a/frontend/src/types/table.ts b/frontend/src/types/table.tsdeleted file mode 100644index 200d1094ac..0000000000--- a/frontend/src/types/table.ts+++ /dev/null@@ -1,36 +0,0 @@-import { Column } from "./column";-import { Database } from "./database";-import { TableId } from "./id";-import { Principal } from "./principal";-import { TableIndex } from "./tableIndex";--export type TableType = "BASE TABLE" | "VIEW";-export type TableEngineType = "InnoDB";--// Table-export type Table = {- id: TableId;-- // Related fields- database: Database;-- // Standard fields- creator: Principal;- createdTs: number;- updater: Principal;- updatedTs: number;-- // Domain specific fields- name: string;- type: TableType;- engine: TableEngineType;- collation: string;- rowCount: number;- dataSize: number;- indexList: TableIndex[];- indexSize: number;- dataFree: number;- createOptions: string;- comment: string;- columnList: Column[];-};diff --git a/frontend/src/types/tableIndex.ts b/frontend/src/types/tableIndex.tsindex 318a008d28..499412d88a 100644--- a/frontend/src/types/tableIndex.ts+++ b/frontend/src/types/tableIndex.ts@@ -1,12 +1,13 @@-import { DatabaseId, TableId, TableIndexId } from "./id";+import { DatabaseId, IdType, TableIndexId } from "./id";+// TODO(steven): remove it.// Indexexport type TableIndex = {id: TableIndexId;// Related fieldsdatabaseId: DatabaseId;- tableId: TableId;+ tableId: IdType;// Standard fieldscreatorId: number;diff --git a/frontend/src/utils/sql-editor.ts b/frontend/src/utils/sql-editor.tsindex 185bab6962..9e86962243 100644--- a/frontend/src/utils/sql-editor.ts+++ b/frontend/src/utils/sql-editor.ts@@ -1,10 +1,11 @@+import { has, uniqueId } from "lodash-es";import {ConnectionAtom,ConnectionAtomType,Database,Instance,- Table,} from "@/types";+import { TableMetadata } from "@/types/proto/database";export const mapConnectionAtom =(@@ -12,16 +13,17 @@ export const mapConnectionAtom =parentId: number,overrides: Partial<ConnectionAtom> = {}) =>- (item: Instance | Database | Table) => {+ (item: Instance | Database | TableMetadata) => {+ const atomId =+ type !== "table" && has(item, "id") ? (item as any).id : uniqueId();const connectionAtom: ConnectionAtom = {parentId,- id: item.id,- key: `${type}-${item.id}`,+ id: atomId,+ key: `${type}-${atomId}`,label: item.name,type,isLeaf: type === "table",...overrides,};-return connectionAtom;};diff --git a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vueindex ebbab4bdd0..2efe6a4f15 100644--- a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue+++ b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue@@ -21,27 +21,27 @@</template><script lang="ts" setup>+import { isUndefined } from "lodash-es";import { computed } from "vue";import { useConnectionTreeStore } from "@/store";import DatabaseTree from "./DatabaseTree.vue";import QueryHistoryContainer from "./QueryHistoryContainer.vue";import TableSchema from "./TableSchema.vue";import { Splitpanes, Pane } from "splitpanes";-import { unknown, UNKNOWN_ID } from "@/types";const FULL_HEIGHT = 100;const DATABASE_PANE_SIZE = 60;const connectionTreeStore = useConnectionTreeStore();const databasePaneSize = computed(() => {- if (connectionTreeStore.selectedTable.id !== UNKNOWN_ID) {+ if (!isUndefined(connectionTreeStore.selectedTableAtom)) {return DATABASE_PANE_SIZE;}return FULL_HEIGHT;});const handleCloseTableSchemaPane = () => {- connectionTreeStore.selectedTable = unknown("TABLE");+ connectionTreeStore.selectedTableAtom = undefined;};</script>diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex ec3e42a772..8afeb08830 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -64,9 +64,9 @@ import {useConnectionTreeStore,useCurrentUser,useDatabaseStore,+ useDBSchemaStore,useInstanceStore,useIsLoggedIn,- useTableStore,useTabStore,} from "@/store";import {@@ -98,7 +98,7 @@ const { t } = useI18n();const instanceStore = useInstanceStore();const databaseStore = useDatabaseStore();const connectionTreeStore = useConnectionTreeStore();-const tableStore = useTableStore();+const dbSchemaStore = useDBSchemaStore();const tabStore = useTabStore();const isLoggedIn = useIsLoggedIn();const currentUser = useCurrentUser();@@ -202,14 +202,9 @@ const setConnection = (const databaseId = option.parentId;const databaseInfo = databaseStore.getDatabaseById(databaseId);const instanceId = databaseInfo.instance.id;- const tableId = option.id;conn.instanceId = instanceId;conn.databaseId = databaseId;- tableStore- .getOrFetchTableByDatabaseIdAndTableId(databaseId, tableId)- .then((table) => {- connectionTreeStore.selectedTable = table;- });+ connectionTreeStore.selectedTableAtom = option;}connect();@@ -225,7 +220,7 @@ const renderLabel = ({ option }: { option: ConnectionAtom }) => {};if (option.type === "table") {- if (option.id === connectionTreeStore.selectedTable.id) {+ if (option === connectionTreeStore.selectedTableAtom) {emphasize();}}@@ -300,7 +295,9 @@ const renderSuffix = ({ option }: { option: ConnectionAtom }) => {const loadSubTree = async (item: ConnectionAtom): Promise<void> => {if (item.type === "database") {- const tableList = await useTableStore().fetchTableListByDatabaseId(item.id);+ const tableList = await dbSchemaStore.getOrFetchTableListByDatabaseId(+ item.id as DatabaseId+ );const mapper = mapConnectionAtom("table", item.id);item.children = tableList.map((table) => generateTableItem(mapper(table)));diff --git a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vueindex 38967d3312..42a2aed83b 100644--- a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue+++ b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue@@ -1,5 +1,5 @@<template>- <div v-if="table.id !== UNKNOWN_ID" class="table-schema">+ <div v-if="table !== undefined" class="table-schema"><div class="table-schema--header"><div class="table-schema--header-title mr-1 flex items-center"><heroicons-outline:table class="h-4 w-4 mr-1" />@@ -45,7 +45,7 @@</div><div class="table-schema--content text-sm text-gray-400 overflow-y-auto"><div- v-for="(column, index) in table.columnList"+ v-for="(column, index) in table.columns":key="index"class="flex justify-between items-center w-full p-1 hover:bg-link-hover">@@ -64,26 +64,42 @@</template><script lang="ts" setup>+import { isUndefined } from "lodash-es";import { computed } from "vue";import { stringify } from "qs";-import type { Repository } from "@/types";-import { baseDirectoryWebUrl, UNKNOWN_ID } from "@/types";-import { useConnectionTreeStore, useRepositoryStore } from "@/store";+import { baseDirectoryWebUrl } from "@/types";+import {+ useConnectionTreeStore,+ useDatabaseStore,+ useDBSchemaStore,+ useRepositoryStore,+} from "@/store";const emit = defineEmits<{(e: "close-pane"): void;}>();const connectionTreeStore = useConnectionTreeStore();-const table = computed(() => connectionTreeStore.selectedTable);+const databaseStore = useDatabaseStore();+const dbSchemaStore = useDBSchemaStore();+const tableAtom = computed(() => connectionTreeStore.selectedTableAtom);+const table = computed(() => {+ if (isUndefined(tableAtom.value)) {+ return undefined;+ }+ return dbSchemaStore.getTableByDatabaseIdAndTableName(+ tableAtom.value.parentId,+ tableAtom.value.label+ );+});const gotoAlterSchema = () => {- if (table.value.id === UNKNOWN_ID) {+ if (isUndefined(tableAtom.value) || isUndefined(table.value)) {return;}- const { database } = table.value;+ const database = databaseStore.getDatabaseById(tableAtom.value.parentId);const { project } = database;if (project.workflowType === "VCS") {useRepositoryStore()diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vueindex 464d849b63..d229a3b6cf 100644--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue@@ -24,12 +24,18 @@ import {useTabStore,useSQLEditorStore,useDatabaseStore,- useTableStore,useSheetStore,useInstanceById,+ useDBSchemaStore,} from "@/store";import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";-import type { ExecuteConfig, ExecuteOption, SQLDialect } from "@/types";+import type {+ Database,+ ExecuteConfig,+ ExecuteOption,+ SQLDialect,+} from "@/types";+import { TableMetadata } from "@/types/proto/database";const emit = defineEmits<{(e: "save-sheet", content?: string): void;@@ -44,7 +50,7 @@ const emit = defineEmits<{const instanceStore = useInstanceStore();const tabStore = useTabStore();const databaseStore = useDatabaseStore();-const tableStore = useTableStore();+const dbSchemaStore = useDBSchemaStore();const sqlEditorStore = useSQLEditorStore();const sheetStore = useSheetStore();@@ -152,16 +158,19 @@ const handleEditorReady = async () => {},});- watchEffect(() => {+ watchEffect(async () => {if (selectedInstance.value) {+ const databaseMap: Map<Database, TableMetadata[]> = new Map();const databaseList = databaseStore.getDatabaseListByInstanceId(selectedInstance.value.id);- const tableList = databaseList- .map((item) => tableStore.getTableListByDatabaseId(item.id))- .flat();-- editorRef.value?.setEditorAutoCompletionContext(databaseList, tableList);+ for (const database of databaseList) {+ const tableList = await dbSchemaStore.getOrFetchTableListByDatabaseId(+ database.id+ );+ databaseMap.set(database, tableList);+ }+ editorRef.value?.setEditorAutoCompletionContext(databaseMap);}});};diff --git a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vueindex a2fffd789b..99e79a7c5a 100644--- a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue+++ b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue@@ -38,11 +38,12 @@ import {useTabStore,useSQLEditorStore,useDatabaseStore,- useTableStore,+ useDBSchemaStore,useInstanceById,} from "@/store";import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";-import { ExecuteConfig, ExecuteOption, SQLDialect } from "@/types";+import { Database, ExecuteConfig, ExecuteOption, SQLDialect } from "@/types";+import { TableMetadata } from "@/types/proto/database";const props = defineProps({sql: {@@ -71,7 +72,7 @@ const MIN_EDITOR_HEIGHT = 40; // ~= 1 lineconst instanceStore = useInstanceStore();const tabStore = useTabStore();const databaseStore = useDatabaseStore();-const tableStore = useTableStore();+const dbSchemaStore = useDBSchemaStore();const sqlEditorStore = useSQLEditorStore();const editorRef = ref<InstanceType<typeof MonacoEditor>>();@@ -228,16 +229,19 @@ const handleEditorReady = async () => {"endsWithSemicolon && cursorAtLast");- watchEffect(() => {+ watchEffect(async () => {if (selectedInstance.value) {+ const databaseMap: Map<Database, TableMetadata[]> = new Map();const databaseList = databaseStore.getDatabaseListByInstanceId(selectedInstance.value.id);- const tableList = databaseList- .map((item) => tableStore.getTableListByDatabaseId(item.id))- .flat();-- editorRef.value?.setEditorAutoCompletionContext(databaseList, tableList);+ for (const database of databaseList) {+ const tableList = await dbSchemaStore.getOrFetchTableListByDatabaseId(+ database.id+ );+ databaseMap.set(database, tableList);+ }+ editorRef.value?.setEditorAutoCompletionContext(databaseMap);}});