Skip to content

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

refactor: remove ComposedDatabaseGroup type and simplify data flow (#17343)

boojackca6d1ce878fe
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
index 2ff32fb324..a841e01690 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
@@ -7,7 +7,7 @@
:striped="true"
:bordered="bordered"
:loading="loading"
- :row-key="(data: ComposedDatabaseGroup) => data.name"
+ :row-key="(data: DatabaseGroup) => data.name"
:checked-row-keys="selectedDatabaseGroupNames"
:row-props="rowProps"
:pagination="{ pageSize: 20 }"
@@ -26,15 +26,15 @@ import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
import { getProjectNameAndDatabaseGroupName } from "@/store";
-import type { ComposedDatabaseGroup } from "@/types";
+import type { DatabaseGroup } from "@/types/proto-es/v1/database_group_service_pb";
-type DatabaseGroupDataTableColumn = DataTableColumn<ComposedDatabaseGroup> & {
+type DatabaseGroupDataTableColumn = DataTableColumn<DatabaseGroup> & {
hide?: boolean;
};
const props = withDefaults(
defineProps<{
- databaseGroupList: ComposedDatabaseGroup[];
+ databaseGroupList: DatabaseGroup[];
bordered?: boolean;
loading?: boolean;
customClick?: boolean;
@@ -50,11 +50,7 @@ const props = withDefaults(
);
const emit = defineEmits<{
- (
- event: "row-click",
- e: MouseEvent,
- databaseGroup: ComposedDatabaseGroup
- ): void;
+ (event: "row-click", e: MouseEvent, databaseGroup: DatabaseGroup): void;
(event: "update:selected-database-group-names", val: string[]): void;
}>();
@@ -139,7 +135,7 @@ const data = computed(() => {
return [...props.databaseGroupList];
});
-const rowProps = (databaseGroup: ComposedDatabaseGroup) => {
+const rowProps = (databaseGroup: DatabaseGroup) => {
return {
style: "cursor: pointer;",
onClick: (e: MouseEvent) => {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index ed9b95a96d..485aadb03b 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -75,6 +75,7 @@ import type { ConditionGroupExpr } from "@/plugins/cel";
import {
buildCELExpr,
emptySimpleExpr,
+ resolveCELExpr,
validateSimpleExpr,
wrapAsGroup,
} from "@/plugins/cel";
@@ -94,7 +95,10 @@ import {
DatabaseGroupSchema,
type DatabaseGroup,
} from "@/types/proto-es/v1/database_group_service_pb";
-import { batchConvertParsedExprToCELString } from "@/utils";
+import {
+ batchConvertCELStringToParsedExpr,
+ batchConvertParsedExprToCELString,
+} from "@/utils";
import { ResourceIdField } from "../v2";
import MatchedDatabaseView from "./MatchedDatabaseView.vue";
import {
@@ -146,12 +150,18 @@ onMounted(async () => {
);
state.resourceId = databaseGroupName;
state.placeholder = databaseGroupEntity.title;
- const composedDatabaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
+ const fetchedDatabaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
databaseGroup.name,
{ silent: true }
);
- if (composedDatabaseGroup.simpleExpr) {
- state.expr = cloneDeep(composedDatabaseGroup.simpleExpr);
+ if (fetchedDatabaseGroup?.databaseExpr?.expression) {
+ // Convert CEL expression to simple expression
+ const expressions = [fetchedDatabaseGroup.databaseExpr.expression];
+ const exprList = await batchConvertCELStringToParsedExpr(expressions);
+ if (exprList.length > 0) {
+ const simpleExpr = resolveCELExpr(exprList[0]);
+ state.expr = cloneDeep(wrapAsGroup(simpleExpr));
+ }
}
});
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 6e133dc05e..9425e0bea6 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -14,7 +14,8 @@ import DatabaseGroupDataTable from "@/components/DatabaseGroup/DatabaseGroupData
import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
import { useDBGroupListByProject } from "@/store";
import { getProjectNameAndDatabaseGroupName } from "@/store/modules/v1/common";
-import type { ComposedDatabaseGroup, ComposedProject } from "@/types";
+import type { ComposedProject } from "@/types";
+import type { DatabaseGroup } from "@/types/proto-es/v1/database_group_service_pb";
const props = defineProps<{
project: ComposedProject;
@@ -41,7 +42,7 @@ const filteredDbGroupList = computed(() => {
const handleDatabaseGroupClick = (
event: MouseEvent,
- databaseGroup: ComposedDatabaseGroup
+ databaseGroup: DatabaseGroup
) => {
const [projectId, databaseGroupName] = getProjectNameAndDatabaseGroupName(
databaseGroup.name
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index e4fcee71c0..d4b4ff5367 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -8,17 +8,8 @@ import { computed, ref, unref, watch, watchEffect } from "vue";
import { databaseGroupServiceClientConnect } from "@/grpcweb";
import { silentContextKey } from "@/grpcweb/context-key";
import type { ConditionGroupExpr } from "@/plugins/cel";
-import {
- buildCELExpr,
- emptySimpleExpr,
- resolveCELExpr,
- wrapAsGroup,
-} from "@/plugins/cel";
-import type {
- ComposedDatabase,
- ComposedDatabaseGroup,
- ComposedProject,
-} from "@/types";
+import { buildCELExpr } from "@/plugins/cel";
+import type { ComposedDatabase, ComposedProject } from "@/types";
import { ExprSchema } from "@/types/proto-es/google/type/expr_pb";
import type {
DatabaseGroup,
@@ -33,81 +24,20 @@ import {
DatabaseGroupView as DatabaseGroupViewEnum,
DatabaseGroupSchema,
} from "@/types/proto-es/v1/database_group_service_pb";
-import {
- batchConvertCELStringToParsedExpr,
- batchConvertParsedExprToCELString,
-} from "@/utils";
+import { batchConvertParsedExprToCELString } from "@/utils";
import { useCache } from "../cache";
-import { batchGetOrFetchProjects, useProjectV1Store } from "./v1";
-import {
- databaseGroupNamePrefix,
- getProjectNameAndDatabaseGroupName,
- projectNamePrefix,
-} from "./v1/common";
-
-const batchComposeDatabaseGroup = async (
- databaseGroupList: DatabaseGroup[]
-): Promise<ComposedDatabaseGroup[]> => {
- const composedDatabaseGroupMap: Map<string, ComposedDatabaseGroup> =
- new Map();
- const expressions: string[] = [];
- const composedDatabaseGroupNameList: string[] = [];
-
- const projectStore = useProjectV1Store();
-
- await batchGetOrFetchProjects(
- databaseGroupList.map((databaseGroup) => {
- const [projectName, _] = getProjectNameAndDatabaseGroupName(
- databaseGroup.name
- );
- return `${projectNamePrefix}${projectName}`;
- })
- );
-
- for (const databaseGroup of databaseGroupList) {
- const [projectName, _] = getProjectNameAndDatabaseGroupName(
- databaseGroup.name
- );
- const project = projectStore.getProjectByName(
- `${projectNamePrefix}${projectName}`
- );
-
- composedDatabaseGroupMap.set(databaseGroup.name, {
- ...databaseGroup,
- projectName,
- projectEntity: project,
- simpleExpr: emptySimpleExpr(),
- });
-
- if (databaseGroup.databaseExpr?.expression) {
- expressions.push(databaseGroup.databaseExpr.expression);
- composedDatabaseGroupNameList.push(databaseGroup.name);
- }
- }
-
- const exprList = await batchConvertCELStringToParsedExpr(expressions);
- for (let i = 0; i < exprList.length; i++) {
- const databaseGroupName = composedDatabaseGroupNameList[i];
-
- const celExpr = exprList[i];
- const simpleExpr = resolveCELExpr(celExpr);
- composedDatabaseGroupMap.get(databaseGroupName)!.simpleExpr =
- wrapAsGroup(simpleExpr);
- }
-
- return [...composedDatabaseGroupMap.values()];
-};
+import { databaseGroupNamePrefix } from "./v1/common";
type DatabaseGroupCacheKey = [string /* name */, DatabaseGroupView];
export const useDBGroupStore = defineStore("db-group", () => {
- const cacheByName = useCache<DatabaseGroupCacheKey, ComposedDatabaseGroup>(
+ const cacheByName = useCache<DatabaseGroupCacheKey, DatabaseGroup>(
"bb.database-group.by-name"
);
// Cache utils
const setDatabaseGroupCache = (
- databaseGroup: ComposedDatabaseGroup,
+ databaseGroup: DatabaseGroup,
view: DatabaseGroupView
) => {
if (view === DatabaseGroupViewEnum.FULL) {
@@ -148,10 +78,8 @@ export const useDBGroupStore = defineStore("db-group", () => {
await databaseGroupServiceClientConnect.getDatabaseGroup(request, {
contextValues: createContextValues().set(silentContextKey, silent),
});
- const composedData = await batchComposeDatabaseGroup([databaseGroup]);
- const response = composedData[0];
- setDatabaseGroupCache(response, view);
- return response;
+ setDatabaseGroupCache(databaseGroup, view);
+ return databaseGroup;
};
const fetchDBGroupListByProjectName = async (projectName: string) => {
@@ -160,20 +88,18 @@ export const useDBGroupStore = defineStore("db-group", () => {
});
const { databaseGroups } =
await databaseGroupServiceClientConnect.listDatabaseGroups(request);
- const composedList = [];
- const composeDatabaseGroups =
- await batchComposeDatabaseGroup(databaseGroups);
- for (const composedData of composeDatabaseGroups) {
- setDatabaseGroupCache(composedData, DatabaseGroupViewEnum.BASIC);
- composedList.push(composedData);
+ const databaseGroupList = [];
+ for (const databaseGroup of databaseGroups) {
+ setDatabaseGroupCache(databaseGroup, DatabaseGroupViewEnum.BASIC);
+ databaseGroupList.push(databaseGroup);
}
- return composedList;
+ return databaseGroupList;
};
const getDBGroupByName = (
name: string,
view?: DatabaseGroupView
- ): ComposedDatabaseGroup | undefined => {
+ ): DatabaseGroup | undefined => {
if (!view) {
return (
cacheByName.getEntity([name, DatabaseGroupViewEnum.FULL]) ??
@@ -218,10 +144,7 @@ export const useDBGroupStore = defineStore("db-group", () => {
),
});
if (!validateOnly) {
- const composedData = await batchComposeDatabaseGroup([
- createdDatabaseGroup,
- ]);
- setDatabaseGroupCache(composedData[0], DatabaseGroupViewEnum.FULL);
+ setDatabaseGroupCache(createdDatabaseGroup, DatabaseGroupViewEnum.FULL);
}
return createdDatabaseGroup;
};
@@ -236,10 +159,7 @@ export const useDBGroupStore = defineStore("db-group", () => {
});
const updatedDatabaseGroup =
await databaseGroupServiceClientConnect.updateDatabaseGroup(request);
- const composedData = await batchComposeDatabaseGroup([
- updatedDatabaseGroup,
- ]);
- setDatabaseGroupCache(composedData[0], DatabaseGroupViewEnum.FULL);
+ setDatabaseGroupCache(updatedDatabaseGroup, DatabaseGroupViewEnum.FULL);
return updatedDatabaseGroup;
};
@@ -303,7 +223,7 @@ export const useDBGroupStore = defineStore("db-group", () => {
export const useDBGroupListByProject = (project: MaybeRef<string>) => {
const store = useDBGroupStore();
const ready = ref(false);
- const dbGroupList = ref<ComposedDatabaseGroup[]>([]);
+ const dbGroupList = ref<DatabaseGroup[]>([]);
watchEffect(() => {
ready.value = false;
diff --git a/frontend/src/types/dbGroup.ts b/frontend/src/types/dbGroup.ts
index 66601bdf5a..3648a77505 100644
--- a/frontend/src/types/dbGroup.ts
+++ b/frontend/src/types/dbGroup.ts
@@ -1,13 +1,5 @@
-import type { ConditionGroupExpr } from "@/plugins/cel";
-import { UNKNOWN_ID, type ComposedProject } from "@/types";
+import { UNKNOWN_ID } from "@/types";
import { extractDatabaseGroupName } from "@/utils";
-import type { DatabaseGroup } from "./proto-es/v1/database_group_service_pb";
-
-export interface ComposedDatabaseGroup extends DatabaseGroup {
- projectName: string;
- projectEntity: ComposedProject;
- simpleExpr: ConditionGroupExpr;
-}
export const isValidDatabaseGroupName = (name: string): boolean => {
if (typeof name !== "string") return false;
diff --git a/frontend/src/utils/databaseGroup/issue.ts b/frontend/src/utils/databaseGroup/issue.ts
index 1ceed607d2..607441a711 100644
--- a/frontend/src/utils/databaseGroup/issue.ts
+++ b/frontend/src/utils/databaseGroup/issue.ts
@@ -1,12 +1,12 @@
import dayjs from "dayjs";
import type { LocationQueryRaw } from "vue-router";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
-import type { ComposedDatabaseGroup } from "@/types";
+import type { DatabaseGroup } from "@/types/proto-es/v1/database_group_service_pb";
import { extractProjectResourceName } from "../v1";
export const generateDatabaseGroupIssueRoute = (
type: "bb.issue.database.schema.update" | "bb.issue.database.data.update",
- databaseGroup: ComposedDatabaseGroup,
+ databaseGroup: DatabaseGroup,
sql = ""
) => {
const issueNameParts: string[] = [];