Skip to content

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

refactor: use db_schema instead of view and extension in frontend (#3923)

boojackdc94985ed534
diff --git a/frontend/src/components/DBExtensionTable.vue b/frontend/src/components/DBExtensionTable.vue
index b35c488299..3ce693b61c 100644
--- a/frontend/src/components/DBExtensionTable.vue
+++ b/frontend/src/components/DBExtensionTable.vue
@@ -26,8 +26,8 @@
<script lang="ts">
import { computed, PropType } from "vue";
-import { DBExtension } from "../types";
import { useI18n } from "vue-i18n";
+import { ExtensionMetadata } from "@/types/proto/database";
export default {
name: "DbExtensionTable",
@@ -35,7 +35,7 @@ export default {
props: {
dbExtensionList: {
required: true,
- type: Object as PropType<DBExtension[]>,
+ type: Object as PropType<ExtensionMetadata[]>,
},
},
setup() {
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 0b767a5977..ef7a4537b5 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -213,8 +213,6 @@ import {
featureToRef,
useCurrentUser,
useDataSourceStore,
- useViewStore,
- useDBExtensionStore,
useAnomalyList,
useDBSchemaStore,
} from "@/store";
@@ -246,8 +244,6 @@ export default defineComponent({
const currentUser = useCurrentUser();
const dbSchemaStore = useDBSchemaStore();
- const viewStore = useViewStore();
- const dbExtensionStore = useDBExtensionStore();
const databaseEngine = props.database.instance.engine as EngineType;
@@ -257,18 +253,6 @@ export default defineComponent({
watchEffect(prepareDatabaseMetadata);
- const prepareViewList = () => {
- viewStore.fetchViewListByDatabaseId(props.database.id);
- };
-
- watchEffect(prepareViewList);
-
- const prepareDBExtensionList = () => {
- dbExtensionStore.fetchdbExtensionListByDatabaseId(props.database.id);
- };
-
- watchEffect(prepareDBExtensionList);
-
const anomalyList = useAnomalyList(
computed(() => ({ databaseId: props.database.id }))
);
@@ -293,11 +277,11 @@ export default defineComponent({
});
const viewList = computed(() => {
- return viewStore.getViewListByDatabaseId(props.database.id);
+ return dbSchemaStore.getViewListByDatabaseId(props.database.id);
});
const dbExtensionList = computed(() => {
- return dbExtensionStore.getDBExtensionListByDatabaseId(props.database.id);
+ return dbSchemaStore.getExtensionListByDatabaseId(props.database.id);
});
const allowConfigInstance = computed(() => {
diff --git a/frontend/src/components/ViewTable.vue b/frontend/src/components/ViewTable.vue
index 2a2999a9b3..c1dc61e1d3 100644
--- a/frontend/src/components/ViewTable.vue
+++ b/frontend/src/components/ViewTable.vue
@@ -17,9 +17,6 @@
<BBTableCell class="w-8">
{{ view.comment }}
</BBTableCell>
- <BBTableCell class="w-8">
- {{ humanizeTs(view.createdTs) }}
- </BBTableCell>
</template>
</BBTable>
</template>
@@ -27,7 +24,7 @@
<script lang="ts">
import { computed, PropType } from "vue";
import { useI18n } from "vue-i18n";
-import { View } from "@/types";
+import { ViewMetadata } from "@/types/proto/database";
export default {
name: "ViewTable",
@@ -35,7 +32,7 @@ export default {
props: {
viewList: {
required: true,
- type: Object as PropType<View[]>,
+ type: Object as PropType<ViewMetadata[]>,
},
},
setup() {
@@ -50,9 +47,6 @@ export default {
{
title: t("database.comment"),
},
- {
- title: t("common.created-at"),
- },
]);
return {
diff --git a/frontend/src/store/modules/dbExtension.ts b/frontend/src/store/modules/dbExtension.ts
deleted file mode 100644
index 7ede2bf705..0000000000
--- a/frontend/src/store/modules/dbExtension.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { defineStore } from "pinia";
-import axios from "axios";
-import {
- Database,
- DatabaseId,
- ResourceIdentifier,
- ResourceObject,
- unknown,
- DBExtension,
- DBExtensionState,
-} from "@/types";
-import { getPrincipalFromIncludedList } from "./principal";
-import { useDatabaseStore } from "./database";
-
-function convert(
- dbExtension: ResourceObject,
- includedList: ResourceObject[]
-): DBExtension {
- const databaseId = (
- dbExtension.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;
- }
- }
-
- return {
- ...(dbExtension.attributes as Omit<
- DBExtension,
- "id" | "database" | "creator" | "updater"
- >),
- id: parseInt(dbExtension.id),
- creator: getPrincipalFromIncludedList(
- dbExtension.relationships!.creator.data,
- includedList
- ),
- updater: getPrincipalFromIncludedList(
- dbExtension.relationships!.updater.data,
- includedList
- ),
- database,
- };
-}
-
-export const useDBExtensionStore = defineStore("dbExtension", {
- state: (): DBExtensionState => ({
- dbExtensionListByDatabaseId: new Map(),
- }),
-
- actions: {
- getDBExtensionListByDatabaseId(databaseId: DatabaseId): DBExtension[] {
- return this.dbExtensionListByDatabaseId.get(databaseId) || [];
- },
-
- async fetchdbExtensionListByDatabaseId(databaseId: DatabaseId) {
- const data = (await axios.get(`/api/database/${databaseId}/extension`))
- .data;
- const dbExtensionList = data.data.map((dbExtension: ResourceObject) => {
- return convert(dbExtension, data.included);
- });
-
- this.dbExtensionListByDatabaseId.set(databaseId, dbExtensionList);
- return dbExtensionList;
- },
- },
-});
diff --git a/frontend/src/store/modules/dbSchema.ts b/frontend/src/store/modules/dbSchema.ts
index 3d31e48c12..f4ff95aca6 100644
--- a/frontend/src/store/modules/dbSchema.ts
+++ b/frontend/src/store/modules/dbSchema.ts
@@ -1,7 +1,12 @@
import axios from "axios";
import { defineStore } from "pinia";
import { DatabaseId, DBSchemaState } from "@/types";
-import { DatabaseMetadata, TableMetadata } from "@/types/proto/database";
+import {
+ DatabaseMetadata,
+ ExtensionMetadata,
+ TableMetadata,
+ ViewMetadata,
+} from "@/types/proto/database";
export const useDBSchemaStore = defineStore("dbSchema", {
state: (): DBSchemaState => ({
@@ -55,5 +60,42 @@ export const useDBSchemaStore = defineStore("dbSchema", {
const tableList = this.getTableListByDatabaseId(databaseId);
return tableList.find((table) => table.name === tableName);
},
+ async getOrFetchViewListByDatabaseId(
+ databaseId: DatabaseId
+ ): Promise<ViewMetadata[]> {
+ if (!this.databaseMetadataById.has(databaseId)) {
+ await this.getOrFetchDatabaseMetadataById(databaseId);
+ }
+ return this.getViewListByDatabaseId(databaseId);
+ },
+ getViewListByDatabaseId(databaseId: DatabaseId): ViewMetadata[] {
+ const databaseMetadata = this.databaseMetadataById.get(databaseId);
+ if (!databaseMetadata) {
+ return [];
+ }
+
+ const viewList: ViewMetadata[] = [];
+ // TODO(steven): get view list with schema name for PG.
+ for (const schema of databaseMetadata.schemas) {
+ viewList.push(...schema.views);
+ }
+ return viewList;
+ },
+ async getOrFetchExtensionListByDatabaseId(
+ databaseId: DatabaseId
+ ): Promise<ExtensionMetadata[]> {
+ if (!this.databaseMetadataById.has(databaseId)) {
+ await this.getOrFetchDatabaseMetadataById(databaseId);
+ }
+ return this.getExtensionListByDatabaseId(databaseId);
+ },
+ getExtensionListByDatabaseId(databaseId: DatabaseId): ExtensionMetadata[] {
+ const databaseMetadata = this.databaseMetadataById.get(databaseId);
+ if (!databaseMetadata) {
+ return [];
+ }
+
+ return databaseMetadata.extensions;
+ },
},
});
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 2cba98b7e3..797a439537 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -39,8 +39,6 @@ export * from "./tab";
export * from "./task";
export * from "./uistate";
export * from "./vcs";
-export * from "./view";
-export * from "./dbExtension";
export * from "./sqlReview";
export * from "./onboardingGuide";
export * from "./schemaEditor";
diff --git a/frontend/src/store/modules/view.ts b/frontend/src/store/modules/view.ts
deleted file mode 100644
index 8dea67ed74..0000000000
--- a/frontend/src/store/modules/view.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { defineStore } from "pinia";
-import axios from "axios";
-import {
- Database,
- DatabaseId,
- ResourceIdentifier,
- ResourceObject,
- unknown,
- View,
- ViewState,
-} from "@/types";
-import { getPrincipalFromIncludedList } from "./principal";
-import { useDatabaseStore } from "./database";
-
-function convert(view: ResourceObject, includedList: ResourceObject[]): View {
- const databaseId = (view.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;
- }
- }
-
- return {
- ...(view.attributes as Omit<
- View,
- "id" | "database" | "creator" | "updater"
- >),
- id: parseInt(view.id),
- creator: getPrincipalFromIncludedList(
- view.relationships!.creator.data,
- includedList
- ),
- updater: getPrincipalFromIncludedList(
- view.relationships!.updater.data,
- includedList
- ),
- database,
- };
-}
-
-export const useViewStore = defineStore("view", {
- state: (): ViewState => ({
- viewListByDatabaseId: new Map(),
- }),
-
- actions: {
- getViewListByDatabaseId(databaseId: DatabaseId): View[] {
- return this.viewListByDatabaseId.get(databaseId) || [];
- },
-
- async fetchViewListByDatabaseId(databaseId: DatabaseId) {
- const data = (await axios.get(`/api/database/${databaseId}/view`)).data;
- const viewList = data.data.map((view: ResourceObject) => {
- return convert(view, data.included);
- });
-
- this.viewListByDatabaseId.set(databaseId, viewList);
- return viewList;
- },
- },
-});
diff --git a/frontend/src/types/column.ts b/frontend/src/types/column.ts
deleted file mode 100644
index 56387c944f..0000000000
--- a/frontend/src/types/column.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { ColumnId, DatabaseId, IdType } from "./id";
-
-// TODO(steven): remove it.
-// Column
-export type Column = {
- id: ColumnId;
-
- // Related fields
- databaseId: DatabaseId;
- tableId: IdType;
-
- // Standard fields
- creatorId: number;
- createdTs: number;
- updaterId: number;
- updatedTs: number;
-
- // Domain specific fields
- name: string;
- position: number;
- default?: string;
- nullable: boolean;
- type: string;
- characterSet: string;
- collation: string;
- comment: string;
-};
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 15c83dc0b5..0bdf91f918 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 { Column } from "./column";
// System bot id
export const SYSTEM_BOT_ID = 1;
@@ -130,9 +129,7 @@ export type ResourceType =
| "ANOMALY"
| "DEPLOYMENT_CONFIG"
| "SHEET"
- | "SQL_REVIEW"
- | "TABLE"
- | "COLUMN";
+ | "SQL_REVIEW";
interface ResourceMaker {
(type: "PRINCIPAL"): Principal;
@@ -160,7 +157,6 @@ interface ResourceMaker {
(type: "DEPLOYMENT_CONFIG"): DeploymentConfig;
(type: "SHEET"): Sheet;
(type: "SQL_REVIEW"): SQLReviewPolicy;
- (type: "COLUMN"): Column;
}
const makeUnknown = (type: ResourceType) => {
@@ -520,24 +516,6 @@ const makeUnknown = (type: ResourceType) => {
ruleList: [],
};
- // TODO(steven): remove UNKNOWN_COLUMN
- const UNKNOWN_COLUMN: Column = {
- id: UNKNOWN_ID,
- databaseId: UNKNOWN_DATABASE.id,
- tableId: UNKNOWN_ID,
- creatorId: UNKNOWN_PRINCIPAL.id,
- createdTs: 0,
- updaterId: UNKNOWN_PRINCIPAL.id,
- updatedTs: 0,
- name: "",
- position: 0,
- nullable: true,
- type: "",
- characterSet: "",
- collation: "",
- comment: "",
- };
-
switch (type) {
case "PRINCIPAL":
return UNKNOWN_PRINCIPAL;
@@ -589,8 +567,6 @@ const makeUnknown = (type: ResourceType) => {
return UNKNOWN_SHEET;
case "SQL_REVIEW":
return UNKNOWN_SQL_REVIEW_POLICY;
- case "COLUMN":
- return UNKNOWN_COLUMN;
}
};
export const unknown = makeUnknown as ResourceMaker;
@@ -1001,8 +977,6 @@ const makeEmpty = (type: ResourceType) => {
return EMPTY_SHEET;
case "SQL_REVIEW":
return EMPTY_SQL_REVIEW_POLICY;
- case "TABLE":
- return EMPTY_TABLE;
}
};
export const empty = makeEmpty as ResourceMaker;
diff --git a/frontend/src/types/connectionTree.ts b/frontend/src/types/connectionTree.ts
index 17ade46aac..c09de2c093 100644
--- a/frontend/src/types/connectionTree.ts
+++ b/frontend/src/types/connectionTree.ts
@@ -1,4 +1,4 @@
-import { InstanceId, DatabaseId, ViewId } from "../types";
+import { InstanceId, DatabaseId } from "../types";
export type ConnectionAtomType = "instance" | "database" | "table" | "view";
@@ -9,8 +9,8 @@ export enum ConnectionTreeState {
}
export interface ConnectionAtom {
- parentId: InstanceId | DatabaseId | ViewId;
- id: InstanceId | DatabaseId | ViewId;
+ parentId: InstanceId | DatabaseId;
+ id: InstanceId | DatabaseId;
key: string;
label: string;
type?: ConnectionAtomType;
diff --git a/frontend/src/types/db_extension.ts b/frontend/src/types/db_extension.ts
deleted file mode 100644
index 406f7e4bb5..0000000000
--- a/frontend/src/types/db_extension.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { Database } from "./database";
-import { DBExtensionId } from "./id";
-import { Principal } from "./principal";
-
-// DBExtension
-export type DBExtension = {
- id: DBExtensionId;
-
- // Related fields
- database: Database;
-
- // Standard fields
- creator: Principal;
- createdTs: number;
- updater: Principal;
- updatedTs: number;
-
- // Domain specific fields
- name: string;
- version: string;
- schema: string;
- description: string;
-};
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index 256cf01652..f0d48082fa 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -45,14 +45,6 @@ export type DataSourceId = IdType;
export type DatabaseId = IdType;
-export type ViewId = IdType;
-
-export type DBExtensionId = IdType;
-
-export type ColumnId = IdType;
-
-export type TableIndexId = IdType;
-
export type VCSId = IdType;
export type RepositoryId = IdType;
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 425fbb15f5..faa3d0dd7e 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -5,7 +5,6 @@ export * from "./auditLog";
export * from "./auth";
export * from "./backup";
export * from "./bookmark";
-export * from "./column";
export * from "./common";
export * from "./const";
export * from "./database";
@@ -34,10 +33,7 @@ export * from "./repository";
export * from "./sql";
export * from "./sqlAdvice";
export * from "./store";
-export * from "./tableIndex";
export * from "./vcs";
-export * from "./view";
-export * from "./db_extension";
export * from "./label";
export * from "./deployment";
export * from "./sqlEditor";
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 5cb3d03e3d..1ea023ba41 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -7,8 +7,6 @@ import {
Policy,
PolicyType,
QueryHistory,
- View,
- DBExtension,
Sheet,
OnboardingGuideType,
PolicyResourceType,
@@ -159,14 +157,6 @@ export interface DBSchemaState {
databaseMetadataById: Map<DatabaseId, DatabaseMetadata>;
}
-export interface ViewState {
- viewListByDatabaseId: Map<DatabaseId, View[]>;
-}
-
-export interface DBExtensionState {
- dbExtensionListByDatabaseId: Map<DatabaseId, DBExtension[]>;
-}
-
export interface BackupState {
backupList: Map<DatabaseId, Backup[]>;
}
diff --git a/frontend/src/types/tableIndex.ts b/frontend/src/types/tableIndex.ts
deleted file mode 100644
index 499412d88a..0000000000
--- a/frontend/src/types/tableIndex.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { DatabaseId, IdType, TableIndexId } from "./id";
-
-// TODO(steven): remove it.
-// Index
-export type TableIndex = {
- id: TableIndexId;
-
- // Related fields
- databaseId: DatabaseId;
- tableId: IdType;
-
- // Standard fields
- creatorId: number;
- createdTs: number;
- updaterId: number;
- updatedTs: number;
-
- // Domain specific fields
- name: string;
- expression: string;
- position: number;
- type: string;
- unique: boolean;
- visible: boolean;
- comment: string;
-};
diff --git a/frontend/src/types/view.ts b/frontend/src/types/view.ts
deleted file mode 100644
index e05a6d5537..0000000000
--- a/frontend/src/types/view.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { Database } from "./database";
-import { ViewId } from "./id";
-import { Principal } from "./principal";
-
-// View
-export type View = {
- id: ViewId;
-
- // Related fields
- database: Database;
-
- // Standard fields
- creator: Principal;
- createdTs: number;
- updater: Principal;
- updatedTs: number;
-
- // Domain specific fields
- name: string;
- definition: string;
- comment: string;
-};