Skip to content

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

feat: implement database/schema group selector in alter schema form (#6386)

boojacka41c577467d8
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index a0578c158a..57c8c84196 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -29,7 +29,28 @@
:tab="$t('alter-schema.alter-multiple-db')"
name="MULTI_DB"
>
+ <div class="px-1 space-x-2 mb-4">
+ <NRadio
+ :checked="state.databaseSelectedTab === 'DATABASE'"
+ value="DATABASE"
+ name="database-tab"
+ @update:checked="state.databaseSelectedTab = 'DATABASE'"
+ >
+ Database
+ </NRadio>
+ <NRadio
+ :checked="state.databaseSelectedTab === 'DATABASE_GROUP'"
+ value="DATABASE_GROUP"
+ name="database-tab"
+ @update:checked="
+ state.databaseSelectedTab = 'DATABASE_GROUP'
+ "
+ >
+ Database group
+ </NRadio>
+ </div>
<div
+ v-if="state.databaseSelectedTab === 'DATABASE'"
class="overflow-y-auto"
style="max-height: calc(100vh - 400px)"
>
@@ -51,10 +72,10 @@
v-if="renderedDatabaseList.length > 0"
type="checkbox"
class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
- v-bind="getAllSelectionState(renderedDatabaseList)"
+ v-bind="getAllSelectionState(renderedDatabaseList as ComposedDatabase[])"
@input="
toggleAllDatabasesSelection(
- renderedDatabaseList,
+ renderedDatabaseList as ComposedDatabase[],
($event.target as HTMLInputElement).checked
)
"
@@ -75,6 +96,22 @@
:database-list="schemalessDatabaseList"
/>
</div>
+ <div
+ v-else-if="state.databaseSelectedTab === 'DATABASE_GROUP'"
+ class="overflow-y-auto"
+ style="max-height: calc(100vh - 340px)"
+ >
+ <SelectSchemaGroupsTable
+ :database-group-list="databaseGroupList"
+ :selected-database-group-name="
+ state.selectedDatabaseGroupName
+ "
+ :selected-schema-group-name-list="
+ state.selectedSchemaGroupNameList
+ "
+ @update="handleDatabaseGroupSelect"
+ />
+ </div>
</NTabPane>
<template #suffix>
<BBTableSearch
@@ -124,15 +161,39 @@
</template>
</template>
<template v-else>
- <aside class="flex justify-end mb-4">
- <BBTableSearch
- class="m-px"
- :placeholder="$t('database.search-database')"
- @change-text="(text: string) => (state.searchText = text)"
- />
- </aside>
+ <div class="w-full flex flex-row justify-between items-center mb-2">
+ <div class="px-1 space-x-2">
+ <NRadio
+ :checked="state.databaseSelectedTab === 'DATABASE'"
+ value="DATABASE"
+ name="database-tab"
+ @update:checked="state.databaseSelectedTab = 'DATABASE'"
+ >
+ Database
+ </NRadio>
+ <NRadio
+ :checked="state.databaseSelectedTab === 'DATABASE_GROUP'"
+ value="DATABASE_GROUP"
+ name="database-tab"
+ @update:checked="state.databaseSelectedTab = 'DATABASE_GROUP'"
+ >
+ Database group
+ </NRadio>
+ </div>
+ <aside class="flex justify-end">
+ <BBTableSearch
+ class="m-px"
+ :placeholder="$t('database.search-database')"
+ @change-text="(text: string) => (state.searchText = text)"
+ />
+ </aside>
+ </div>
<!-- a simple table -->
- <div class="overflow-y-auto" style="max-height: calc(100vh - 340px)">
+ <div
+ v-if="state.databaseSelectedTab === 'DATABASE'"
+ class="overflow-y-auto"
+ style="max-height: calc(100vh - 340px)"
+ >
<DatabaseV1Table
mode="ALL_SHORT"
table-class="border"
@@ -147,6 +208,20 @@
:database-list="schemalessDatabaseList"
/>
</div>
+ <div
+ v-else-if="state.databaseSelectedTab === 'DATABASE_GROUP'"
+ class="overflow-y-auto"
+ style="max-height: calc(100vh - 340px)"
+ >
+ <SelectSchemaGroupsTable
+ :database-group-list="databaseGroupList"
+ :selected-database-group-name="state.selectedDatabaseGroupName"
+ :selected-schema-group-name-list="
+ state.selectedSchemaGroupNameList
+ "
+ @update="handleDatabaseGroupSelect"
+ />
+ </div>
</template>
</div>
<div
@@ -220,14 +295,14 @@
</template>
<script lang="ts" setup>
+import { useEventListener } from "@vueuse/core";
import dayjs from "dayjs";
+import { cloneDeep } from "lodash-es";
+import { NTabs, NTabPane, NRadio } from "naive-ui";
import { computed, reactive, PropType, ref } from "vue";
import { useRouter } from "vue-router";
-import { NTabs, NTabPane } from "naive-ui";
-import { useEventListener } from "@vueuse/core";
-import { cloneDeep } from "lodash-es";
-import { ComposedDatabase, UNKNOWN_ID } from "@/types";
+import { ComposedDatabase, ComposedDatabaseGroup, UNKNOWN_ID } from "@/types";
import {
allowGhostMigrationV1,
allowUsingSchemaEditorV1,
@@ -242,7 +317,11 @@ import {
useDatabaseV1Store,
useEnvironmentV1List,
useProjectV1Store,
+ useDBGroupStore,
} from "@/store";
+import { DatabaseV1Table } from "../v2";
+import { Project, TenantMode } from "@/types/proto/v1/project_service";
+import { State } from "@/types/proto/v1/common";
import ProjectStandardView, {
ProjectStandardViewState,
} from "./ProjectStandardView.vue";
@@ -252,17 +331,20 @@ import ProjectTenantView, {
import SchemalessDatabaseTable from "./SchemalessDatabaseTable.vue";
import GhostDialog from "./GhostDialog.vue";
import SchemaEditorModal from "./SchemaEditorModal.vue";
-import { DatabaseV1Table } from "../v2";
-import { Project, TenantMode } from "@/types/proto/v1/project_service";
-import { State } from "@/types/proto/v1/common";
+import { watchEffect } from "vue";
+import SelectSchemaGroupsTable from "../DatabaseGroup/SelectSchemaGroupsTable.vue";
+import { generateIssueRoute } from "@/utils/databaseGroup/issue";
type LocalState = ProjectStandardViewState &
ProjectTenantViewState & {
project?: Project;
searchText: string;
+ databaseSelectedTab: "DATABASE" | "DATABASE_GROUP";
showSchemaLessDatabaseList: boolean;
showSchemaEditorModal: boolean;
showFeatureModal: boolean;
+ selectedDatabaseGroupName?: string;
+ selectedSchemaGroupNameList?: string[];
};
const props = defineProps({
@@ -285,6 +367,7 @@ const router = useRouter();
const currentUserV1 = useCurrentUserV1();
const projectV1Store = useProjectV1Store();
const databaseV1Store = useDatabaseV1Store();
+const dbGroupStore = useDBGroupStore();
const ghostDialog = ref<InstanceType<typeof GhostDialog>>();
const schemaEditorContext = ref<{
@@ -309,6 +392,7 @@ const state = reactive<LocalState>({
deployingTenantDatabaseList: [],
label: "bb.environment",
searchText: "",
+ databaseSelectedTab: "DATABASE",
showSchemaLessDatabaseList: false,
showSchemaEditorModal: false,
showFeatureModal: false,
@@ -335,6 +419,25 @@ const { ready } = useSearchDatabaseV1List({
parent: "instances/-",
});
+const prepareDatabaseGroupList = async () => {
+ let list: ComposedDatabaseGroup[] = [];
+ if (state.project) {
+ list = await dbGroupStore.getOrFetchDBGroupListByProjectName(
+ state.project.name
+ );
+ } else {
+ list = await dbGroupStore.fetchAllDatabaseGroupList();
+ }
+
+ for (const group of list) {
+ await dbGroupStore.getOrFetchSchemaGroupListByDBGroupName(group.name);
+ }
+};
+
+watchEffect(async () => {
+ await prepareDatabaseGroupList();
+});
+
const databaseList = computed(() => {
let list: ComposedDatabase[] = [];
if (props.projectId) {
@@ -373,6 +476,14 @@ const schemalessDatabaseList = computed(() => {
);
});
+const databaseGroupList = computed(() => {
+ if (state.project) {
+ return dbGroupStore.getDBGroupListByProjectName(state.project.name);
+ } else {
+ return dbGroupStore.getAllDatabaseGroupList();
+ }
+});
+
const flattenSelectedDatabaseUidList = computed(() => {
const flattenDatabaseIdList: string[] = [];
if (isTenantProject.value && state.alterType === "MULTI_DB") {
@@ -393,7 +504,11 @@ const showGenerateMultiDb = computed(() => {
});
const allowGenerateMultiDb = computed(() => {
- return flattenSelectedDatabaseUidList.value.length > 0;
+ if (state.databaseSelectedTab === "DATABASE") {
+ return flattenSelectedDatabaseUidList.value.length > 0;
+ } else {
+ return state.selectedDatabaseGroupName;
+ }
});
// 'normal' -> normal migration
@@ -430,6 +545,19 @@ const isUsingGhostMigration = async (databaseList: ComposedDatabase[]) => {
// Also works when single db selected.
const generateMultiDb = async () => {
+ if (state.selectedDatabaseGroupName) {
+ const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
+ state.selectedDatabaseGroupName
+ );
+ const issueRoute = generateIssueRoute(
+ props.type,
+ databaseGroup,
+ state.selectedSchemaGroupNameList
+ );
+ router.push(issueRoute);
+ return;
+ }
+
const selectedDatabaseIdList = [...flattenSelectedDatabaseUidList.value];
const selectedDatabaseList = selectedDatabaseIdList.map(
(id) => schemaDatabaseList.value.find((db) => db.uid === id)!
@@ -480,19 +608,23 @@ const showGenerateTenant = computed(() => {
});
const allowGenerateTenant = computed(() => {
- if (isTenantProject.value && state.alterType === "MULTI_DB") {
- if (state.selectedDatabaseIdListForTenantMode.size === 0) {
- return false;
+ if (state.databaseSelectedTab === "DATABASE") {
+ if (isTenantProject.value && state.alterType === "MULTI_DB") {
+ if (state.selectedDatabaseIdListForTenantMode.size === 0) {
+ return false;
+ }
}
- }
- if (isTenantProject.value) {
- // not allowed when database list filtered by deployment config is empty
- // which means no database will be deployed
- return state.deployingTenantDatabaseList.length > 0;
- }
+ if (isTenantProject.value) {
+ // not allowed when database list filtered by deployment config is empty
+ // which means no database will be deployed
+ return state.deployingTenantDatabaseList.length > 0;
+ }
- return true;
+ return true;
+ } else {
+ return state.selectedDatabaseGroupName;
+ }
});
const getAllSelectionState = (
@@ -525,6 +657,14 @@ const toggleAllDatabasesSelection = (
}
};
+const handleDatabaseGroupSelect = (
+ databaseGroupName: string,
+ schemaGroupNameList: string[]
+) => {
+ state.selectedDatabaseGroupName = databaseGroupName;
+ state.selectedSchemaGroupNameList = schemaGroupNameList;
+};
+
const isDatabaseSelected = (database: ComposedDatabase): boolean => {
return state.selectedDatabaseIdListForTenantMode.has(database.uid);
};
@@ -538,6 +678,19 @@ const toggleDatabaseSelection = (database: ComposedDatabase, on: boolean) => {
};
const generateTenant = async () => {
+ if (state.selectedDatabaseGroupName) {
+ const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
+ state.selectedDatabaseGroupName
+ );
+ const issueRoute = generateIssueRoute(
+ props.type,
+ databaseGroup,
+ state.selectedSchemaGroupNameList
+ );
+ router.push(issueRoute);
+ return;
+ }
+
if (!hasFeature("bb.feature.multi-tenancy")) {
state.showFeatureModal = true;
return;
@@ -547,7 +700,6 @@ const generateTenant = async () => {
if (!projectId) return;
const project = projectV1Store.getProjectByUID(projectId);
-
if (project.uid === String(UNKNOWN_ID)) return;
const query: Record<string, any> = {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index e212a7e5f7..1d65856912 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -58,7 +58,6 @@
/>
</div>
<div class="col-span-2">
- <p class="text-lg mb-2">{{ matchedSectionTitle }}</p>
<MatchedDatabaseView
v-if="resourceType === 'DATABASE_GROUP'"
:project="project"
@@ -135,10 +134,6 @@ const resourceIdType = computed(() =>
props.resourceType === "DATABASE_GROUP" ? "database-group" : "schema-group"
);
-const matchedSectionTitle = computed(() =>
- props.resourceType === "DATABASE_GROUP" ? "Database" : "Table"
-);
-
onMounted(async () => {
const databaseGroup = props.databaseGroup;
if (!databaseGroup) {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
index 512044efac..0a9fbba8b9 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
@@ -19,7 +19,7 @@
<template #footer>
<div class="w-full flex justify-between items-center">
<div>
- <NButton v-if="!isCreating" type="error" @click="doDelete">{{
+ <NButton v-if="showDeleteButton" type="error" @click="doDelete">{{
$t("common.delete")
}}</NButton>
</div>
@@ -41,13 +41,17 @@
<script lang="ts" setup>
import { NButton, NDrawer, NDrawerContent, useDialog } from "naive-ui";
-import { computed, ref } from "vue";
+import { computed, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
import { ComposedProject } from "@/types";
import { DatabaseGroup, SchemaGroup } from "@/types/proto/v1/project_service";
import { Expr } from "@/types/proto/google/type/expr";
import { stringifyDatabaseGroupExpr } from "@/utils/databaseGroup/cel";
-import { useDBGroupStore, useEnvironmentV1Store } from "@/store";
+import {
+ pushNotification,
+ useDBGroupStore,
+ useEnvironmentV1Store,
+} from "@/store";
import { ResourceType } from "./common/ExprEditor/context";
import DatabaseGroupForm from "./DatabaseGroupForm.vue";
import { convertToCELString } from "@/plugins/cel/logic";
@@ -102,7 +106,32 @@ const allowConfirm = computed(() => {
return false;
});
+const showDeleteButton = computed(() => {
+ return !isCreating.value;
+});
+
+const allowDelete = computed(() => {
+ return (
+ props.resourceType === "SCHEMA_GROUP" ||
+ dbGroupStore.getSchemaGroupListByDBGroupName(props.databaseGroup!.name)
+ .length === 0
+ );
+});
+
+onMounted(async () => {
+ await dbGroupStore.fetchAllDatabaseGroupList();
+});
+
const doDelete = () => {
+ if (!allowDelete.value) {
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: "You need to delete related table groups first.",
+ });
+ return;
+ }
+
dialog.error({
title: "Confirm to delete",
positiveText: t("common.confirm"),
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
index b452762489..8599729f8a 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
@@ -1,19 +1,19 @@
<template>
<BBGrid
:column-list="COLUMN_LIST"
- :data-source="formatedDatabaseGroupList"
+ :data-source="databaseGroupList"
:row-clickable="true"
row-key="name"
class="border"
@click-row="clickDatabaseGroup"
>
- <template #item="{ item }: { item: FormatedDatabaseGroup }">
+ <template #item="{ item }: { item: ComposedDatabaseGroup }">
<div class="bb-grid-cell">
- {{ item.resourceId }}
+ {{ item.databaseGroupName }}
</div>
- <div class="bb-grid-cell">{{ item.environment }}</div>
- <div class="bb-grid-cell gap-x-2">
- <NButton size="small" @click.stop="$emit('edit', item.databaseGroup)"
+ <div class="bb-grid-cell">{{ item.environment.title }}</div>
+ <div v-if="props.showEdit" class="bb-grid-cell gap-x-2">
+ <NButton size="small" @click.stop="$emit('edit', item)"
>Configure</NButton
>
</div>
@@ -22,23 +22,16 @@
</template>
<script lang="ts" setup>
-import { computed, ref, watch } from "vue";
+import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBGridColumn } from "@/bbkit";
-import { useEnvironmentV1Store } from "@/store";
-import { getProjectNameAndDatabaseGroupName } from "@/store/modules/v1/common";
import { DatabaseGroup } from "@/types/proto/v1/project_service";
-import { convertDatabaseGroupExprFromCEL } from "@/utils/databaseGroup/cel";
-
-interface FormatedDatabaseGroup {
- resourceId: string;
- environment: string;
- databaseGroup: DatabaseGroup;
-}
+import { ComposedDatabaseGroup } from "@/types";
const props = defineProps<{
- databaseGroupList: DatabaseGroup[];
+ databaseGroupList: ComposedDatabaseGroup[];
+ showEdit?: boolean;
}>();
defineEmits<{
@@ -47,8 +40,6 @@ defineEmits<{
const { t } = useI18n();
const router = useRouter();
-const environmentStore = useEnvironmentV1Store();
-const formatedDatabaseGroupList = ref<FormatedDatabaseGroup[]>([]);
const COLUMN_LIST = computed(() => {
const columns: BBGridColumn[] = [
@@ -57,43 +48,25 @@ const COLUMN_LIST = computed(() => {
title: t("common.environment"),
width: "1fr",
},
- {
+ ];
+
+ if (props.showEdit) {
+ columns.push({
title: "",
width: "10rem",
- },
- ];
+ });
+ }
return columns;
});
-const clickDatabaseGroup = ({ databaseGroup }: FormatedDatabaseGroup) => {
- const [projectName, databaseGroupName] = getProjectNameAndDatabaseGroupName(
- databaseGroup.name
+const clickDatabaseGroup = (databaseGroup: ComposedDatabaseGroup) => {
+ if (!props.showEdit) {
+ return;
+ }
+
+ router.push(
+ `/${databaseGroup.project.name}/database-groups/${databaseGroup.databaseGroupName}`
);
- router.push(`/projects/${projectName}/database-groups/${databaseGroupName}`);
};
-
-watch(
- () => [props.databaseGroupList],
- async () => {
- const list: FormatedDatabaseGroup[] = [];
- for (const databaseGroup of props.databaseGroupList) {
- const convertResult = await convertDatabaseGroupExprFromCEL(
- databaseGroup.databaseExpr?.expression ?? ""
- );
- const environment = environmentStore.getEnvironmentByName(
- convertResult.environmentId
- );
- list.push({
- resourceId: databaseGroup.name.split("/").pop() || "",
- environment: environment?.title || "",
- databaseGroup,
- });
- }
- formatedDatabaseGroupList.value = list;
- },
- {
- immediate: true,
- }
-);
</script>
diff --git a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
index 05501dc217..48304bcfae 100644
--- a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
@@ -1,5 +1,6 @@
<template>
- <div class="w-full border min-h-[20rem]">
+ <p class="text-lg mb-2">Databases</p>
+ <div class="w-full border min-h-[20rem] max-h-[24rem] overflow-y-auto">
<div
class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
>
@@ -19,13 +20,13 @@
<heroicons-outline:chevron-down v-else class="w-5 h-auto" />
</button>
</div>
- <div v-show="state.showMatchedDatabaseList" class="w-full">
+ <div v-show="state.showMatchedDatabaseList" class="w-full py-1">
<div
v-for="database in matchedDatabaseList"
:key="database.name"
class="w-full flex flex-row justify-between items-center px-2 py-1 gap-x-2"
>
- <span>{{ database.databaseName }}</span>
+ <span class="text-sm">{{ database.databaseName }}</span>
<div class="flex flex-row justify-end items-center">
<InstanceV1EngineIcon :instance="database.instanceEntity" />
<span class="ml-1 text-sm text-gray-400">{{
@@ -56,13 +57,13 @@
<heroicons-outline:chevron-down v-else class="w-5 h-auto" />
</button>
</div>
- <div v-show="state.showUnmatchedDatabaseList">
+ <div v-show="state.showUnmatchedDatabaseList" class="w-full py-1">
<div
v-for="database in unmatchedDatabaseList"
:key="database.name"
class="w-full flex flex-row justify-between items-center px-2 py-1 gap-x-2"
>
- <span>{{ database.databaseName }}</span>
+ <span class="text-sm">{{ database.databaseName }}</span>
<div class="flex flex-row justify-end items-center">
<InstanceV1EngineIcon :instance="database.instanceEntity" />
<span class="ml-1 text-sm text-gray-400">{{
@@ -104,7 +105,7 @@ const props = defineProps<{
const environmentStore = useEnvironmentV1Store();
const databaseStore = useDatabaseV1Store();
const state = reactive<LocalState>({
- showMatchedDatabaseList: false,
+ showMatchedDatabaseList: true,
showUnmatchedDatabaseList: false,
});
const matchedDatabaseList = ref<ComposedDatabase[]>([]);
diff --git a/frontend/src/components/DatabaseGroup/MatchedTableView.vue b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
index fb5e46afd4..799410237d 100644
--- a/frontend/src/components/DatabaseGroup/MatchedTableView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
@@ -1,5 +1,6 @@
<template>
- <div class="w-full border min-h-[20rem]">
+ <p class="text-lg mb-2">Tables</p>
+ <div class="w-full border min-h-[20rem] max-h-[24rem] overflow-y-auto">
<div
class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
>
@@ -15,13 +16,13 @@
<heroicons-outline:chevron-down v-else class="w-5 h-auto" />
</button>
</div>
- <div v-show="state.showMatchedTableList" class="w-full">
+ <div v-show="state.showMatchedTableList" class="w-full my-1">
<div
v-for="table in matchedTableList"
:key="table.database"
class="w-full flex flex-row justify-between items-center px-2 py-1 gap-x-2"
>
- <span>{{ table.table }}</span>
+ <span class="text-sm">{{ table.table }}</span>
<div class="flex flex-row justify-end items-center">
<DatabaseView :database-name="table.database" />
</div>
@@ -47,13 +48,13 @@
<heroicons-outline:chevron-down v-else class="w-5 h-auto" />
</button>
</div>
- <div v-show="state.showUnmatchedTableList">
+ <div v-show="state.showUnmatchedTableList" class="w-full py-1">
<div
v-for="table in unmatchedTableList"
:key="table.database"
class="w-full flex flex-row justify-between items-center px-2 py-1 gap-x-2"
>
- <span>{{ table.table }}</span>
+ <span class="text-sm">{{ table.table }}</span>
<div class="flex flex-row justify-end items-center">
<DatabaseView :database-name="table.database" />
</div>
@@ -90,7 +91,7 @@ const props = defineProps<{
}>();
const state = reactive<LocalState>({
- showMatchedTableList: false,
+ showMatchedTableList: true,
showUnmatchedTableList: false,
});
const matchedTableList = ref<SchemaGroup_Table[]>([]);
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 37c5bf5f83..91cd598bef 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -10,6 +10,7 @@
<div class="mt-4">
<DatabaseGroupTable
:database-group-list="databaseGroupList"
+ :show-edit="true"
@edit="handleConfigureDatabaseGroup"
/>
</div>
diff --git a/frontend/src/components/DatabaseGroup/SelectSchemaGroupsTable.vue b/frontend/src/components/DatabaseGroup/SelectSchemaGroupsTable.vue
new file mode 100644
index 0000000000..05f39691af
--- /dev/null
+++ b/frontend/src/components/DatabaseGroup/SelectSchemaGroupsTable.vue
@@ -0,0 +1,154 @@
+<template>
+ <BBGrid
+ :column-list="COLUMN_LIST"
+ :data-source="databaseGroupList"
+ row-key="name"
+ class="border"
+ :row-clickable="true"
+ @click-row="handleDatabaseGroupSelect"
+ >
+ <template #item="{ item: dbGroup }: { item: ComposedDatabaseGroup }">
+ <div class="bb-grid-cell justify-center items-center">
+ <NRadio
+ :checked="state.selectedDatabaseGroupName === dbGroup.name"
+ :value="dbGroup.name"
+ name="database-group"
+ @update:checked="handleDatabaseGroupSelect(dbGroup)"
+ >
+ </NRadio>
+ </div>
+ <div class="bb-grid-cell">
+ {{ dbGroup.databaseGroupName }}
+ </div>
+ <div class="bb-grid-cell">{{ dbGroup.project.title }}</div>
+ <div class="bb-grid-cell">{{ dbGroup.environment.title }}</div>
+ <template v-if="state.selectedDatabaseGroupName === dbGroup.name">
+ <template
+ v-for="schemaGroup in getSchemaGroupListByDBGroupName(dbGroup.name)"
+ :key="schemaGroup.name"
+ >
+ <div class="bb-grid-cell"></div>
+ <div class="bb-grid-cell">
+ <NCheckbox
+ :checked="
+ state.selectedSchemaGroupNameList?.includes(schemaGroup.name)
+ "
+ @update-checked="handleSchemaGroupCheck(schemaGroup)"
+ >
+ <span>{{ getSchemaGroupTitle(schemaGroup.name) }}</span>
+ </NCheckbox>
+ </div>
+ <div class="bb-grid-cell"></div>
+ <div class="bb-grid-cell"></div>
+ </template>
+ </template>
+ </template>
+ </BBGrid>
+</template>
+
+<script lang="ts" setup>
+import { NRadio, NCheckbox } from "naive-ui";
+import { ref, watch, reactive, computed } from "vue";
+import { useDBGroupStore } from "@/store";
+import { ComposedDatabaseGroup } from "@/types";
+import { SchemaGroup } from "@/types/proto/v1/project_service";
+import { getProjectNameAndDatabaseGroupNameAndSchemaGroupName } from "@/store/modules/v1/common";
+import { BBGridColumn } from "@/bbkit";
+import { useI18n } from "vue-i18n";
+
+interface LocalState {
+ selectedDatabaseGroupName?: string;
+ selectedSchemaGroupNameList: string[];
+}
+
+const props = defineProps<{
+ databaseGroupList: ComposedDatabaseGroup[];
+ selectedDatabaseGroupName?: string;
+ selectedSchemaGroupNameList?: string[];
+}>();
+
+const emit = defineEmits<{
+ (event: "update", dbGroupName: string, schemaGroupNameList: string[]): void;
+}>();
+
+const { t } = useI18n();
+const dbGroupStore = useDBGroupStore();
+const state = reactive<LocalState>({
+ selectedDatabaseGroupName: props.selectedDatabaseGroupName,
+ selectedSchemaGroupNameList: props.selectedSchemaGroupNameList || [],
+});
+const schemaGroupListMap = ref<Map<string, SchemaGroup[]>>(new Map());
+
+const COLUMN_LIST = computed(() => {
+ const columns: BBGridColumn[] = [
+ {
+ title: "",
+ width: "2rem",
+ },
+ { title: t("common.name"), width: "1fr" },
+ {
+ title: t("common.project"),
+ width: "1fr",
+ },
+ {
+ title: t("common.environment"),
+ width: "1fr",
+ },
+ ];
+
+ return columns;
+});
+
+const getSchemaGroupListByDBGroupName = (name: string) => {
+ return schemaGroupListMap.value.get(name) || [];
+};
+
+const getSchemaGroupTitle = (name: string) => {
+ const [, , title] =
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName(name);
+ return title || "";
+};
+
+const handleDatabaseGroupSelect = (dbGroup: ComposedDatabaseGroup) => {
+ if (state.selectedDatabaseGroupName === dbGroup.name) {
+ return;
+ }
+
+ state.selectedDatabaseGroupName = dbGroup.name;
+ state.selectedSchemaGroupNameList = [];
+ emit(
+ "update",
+ state.selectedDatabaseGroupName || "",
+ state.selectedSchemaGroupNameList
+ );
+};
+
+const handleSchemaGroupCheck = (schemaGroup: SchemaGroup) => {
+ if (state.selectedSchemaGroupNameList.includes(schemaGroup.name)) {
+ state.selectedSchemaGroupNameList = [];
+ } else {
+ // Note: now we only support one schema group.
+ state.selectedSchemaGroupNameList = [schemaGroup.name];
+ }
+ emit(
+ "update",
+ state.selectedDatabaseGroupName || "",
+ state.selectedSchemaGroupNameList
+ );
+};
+
+watch(
+ () => props,
+ async () => {
+ for (const dbGroup of props.databaseGroupList) {
+ const schemaGroupList =
+ await dbGroupStore.getOrFetchSchemaGroupListByDBGroupName(dbGroup.name);
+ schemaGroupListMap.value.set(dbGroup.name, schemaGroupList);
+ }
+ },
+ {
+ immediate: true,
+ deep: true,
+ }
+);
+</script>
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index b4bde7ab14..a1a3cb4971 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -5,10 +5,12 @@ import { projectServiceClient } from "@/grpcweb";
import { DatabaseGroup, SchemaGroup } from "@/types/proto/v1/project_service";
import { convertDatabaseGroupExprFromCEL } from "@/utils/databaseGroup/cel";
import { useEnvironmentV1Store, useProjectV1Store } from "./v1";
-import { ComposedDatabaseGroup } from "@/types";
+import { ComposedDatabaseGroup, ComposedSchemaGroup } from "@/types";
import { Environment } from "@/types/proto/v1/environment_service";
import {
+ databaseGroupNamePrefix,
getProjectNameAndDatabaseGroupName,
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName,
projectNamePrefix,
} from "./v1/common";
@@ -37,9 +39,26 @@ const composeDatabaseGroup = async (
};
};
+const composeSchemaGroup = async (
+ schemaGroup: SchemaGroup
+): Promise<ComposedSchemaGroup> => {
+ const [projectName, databaseGroupName] =
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName(schemaGroup.name);
+ const databaseGroup = await composeDatabaseGroup(
+ await useDBGroupStore().getOrFetchDBGroupByName(
+ `${projectNamePrefix}${projectName}/${databaseGroupNamePrefix}${databaseGroupName}`
+ )
+ );
+ const composedData: ComposedSchemaGroup = {
+ ...schemaGroup,
+ databaseGroup: databaseGroup,
+ };
+ return composedData;
+};
+
export const useDBGroupStore = defineStore("db-group", () => {
const dbGroupMapByName = ref<Map<string, ComposedDatabaseGroup>>(new Map());
- const schemaGroupMapByName = ref<Map<string, SchemaGroup>>(new Map());
+ const schemaGroupMapByName = ref<Map<string, ComposedSchemaGroup>>(new Map());
const cachedProjectNameSet = ref<Set<string>>(new Set());
const fetchAllDatabaseGroupList = async () => {
@@ -55,6 +74,10 @@ export const useDBGroupStore = defineStore("db-group", () => {
return composedList;
};
+ const getAllDatabaseGroupList = () => {
+ return Array.from(dbGroupMapByName.value.values());
+ };
+
const getOrFetchDBGroupByName = async (name: string) => {
const cached = dbGroupMapByName.value.get(name);
if (cached) return cached;
@@ -64,7 +87,7 @@ export const useDBGroupStore = defineStore("db-group", () => {
});
const composedData = await composeDatabaseGroup(databaseGroup);
dbGroupMapByName.value.set(name, composedData);
- return databaseGroup;
+ return composedData;
};
const getOrFetchDBGroupListByProjectName = async (projectName: string) => {
@@ -78,12 +101,14 @@ export const useDBGroupStore = defineStore("db-group", () => {
const { databaseGroups } = await projectServiceClient.listDatabaseGroups({
parent: projectName,
});
+ const composedList = [];
for (const dbGroup of databaseGroups) {
const composedData = await composeDatabaseGroup(dbGroup);
dbGroupMapByName.value.set(dbGroup.name, composedData);
+ composedList.push(composedData);
}
cachedProjectNameSet.value.add(projectName);
- return databaseGroups;
+ return composedList;
};
const getDBGroupListByProjectName = (projectName: string) => {
@@ -157,7 +182,8 @@ export const useDBGroupStore = defineStore("db-group", () => {
const schemaGroup = await projectServiceClient.getSchemaGroup({
name: name,
});
- schemaGroupMapByName.value.set(name, schemaGroup);
+ const composedData = await composeSchemaGroup(schemaGroup);
+ schemaGroupMapByName.value.set(name, composedData);
return schemaGroup;
};
@@ -167,10 +193,13 @@ export const useDBGroupStore = defineStore("db-group", () => {
const { schemaGroups } = await projectServiceClient.listSchemaGroups({
parent: dbGroupName,
});
+ const composedList: ComposedSchemaGroup[] = [];
for (const schemaGroup of schemaGroups) {
- schemaGroupMapByName.value.set(schemaGroup.name, schemaGroup);
+ const composedData = await composeSchemaGroup(schemaGroup);
+ schemaGroupMapByName.value.set(schemaGroup.name, composedData);
+ composedList.push(composedData);
}
- return schemaGroups;
+ return composedList;
};
const getSchemaGroupListByDBGroupName = (dbGroupName: string) => {
@@ -195,8 +224,9 @@ export const useDBGroupStore = defineStore("db-group", () => {
schemaGroup,
schemaGroupId: name,
});
- schemaGroupMapByName.value.set(createdSchemaGroup.name, createdSchemaGroup);
- return createdSchemaGroup;
+ const composedData = await composeSchemaGroup(createdSchemaGroup);
+ schemaGroupMapByName.value.set(composedData.name, composedData);
+ return composedData;
};
const updateSchemaGroup = async (
@@ -214,8 +244,9 @@ export const useDBGroupStore = defineStore("db-group", () => {
schemaGroup,
updateMask,
});
- schemaGroupMapByName.value.set(updatedSchemaGroup.name, updatedSchemaGroup);
- return updatedSchemaGroup;
+ const composedData = await composeSchemaGroup(updatedSchemaGroup);
+ schemaGroupMapByName.value.set(composedData.name, composedData);
+ return composedData;
};
const deleteSchemaGroup = async (name: string) => {
@@ -227,6 +258,7 @@ export const useDBGroupStore = defineStore("db-group", () => {
return {
fetchAllDatabaseGroupList,
+ getAllDatabaseGroupList,
getOrFetchDBGroupByName,
getOrFetchDBGroupListByProjectName,
getDBGroupListByProjectName,
diff --git a/frontend/src/utils/databaseGroup/issue.ts b/frontend/src/utils/databaseGroup/issue.ts
new file mode 100644
index 0000000000..e62ee04cb8
--- /dev/null
+++ b/frontend/src/utils/databaseGroup/issue.ts
@@ -0,0 +1,34 @@
+import { ComposedDatabaseGroup } from "@/types";
+import dayjs from "dayjs";
+
+export const generateIssueRoute = (
+ type: "bb.issue.database.schema.update" | "bb.issue.database.data.update",
+ databaseGroup: ComposedDatabaseGroup,
+ schemaGroupNameList: string[] = []
+) => {
+ const issueNameParts: string[] = [];
+ issueNameParts.push(`[${databaseGroup.databaseGroupName}]`);
+ issueNameParts.push(
+ type === "bb.issue.database.schema.update" ? `Alter schema` : `Change data`
+ );
+ const datetime = dayjs().format("@MM-DD HH:mm");
+ const tz = "UTC" + dayjs().format("ZZ");
+ issueNameParts.push(`${datetime} ${tz}`);
+
+ const query: Record<string, any> = {
+ template: type,
+ mode: "tenant",
+ name: issueNameParts.join(" "),
+ project: databaseGroup.project.uid,
+ databaseGroupName: databaseGroup.name,
+ schemaGroupNames: schemaGroupNameList.join(","),
+ };
+
+ return {
+ name: "workspace.issue.detail",
+ params: {
+ issueSlug: "new",
+ },
+ query,
+ };
+};
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index c9ce35a58a..0d334ac63b 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -63,6 +63,13 @@
>
Alter Schema
</button>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="createMigration('bb.issue.database.data.update')"
+ >
+ Change Data
+ </button>
</div>
</div>
@@ -78,7 +85,6 @@
/>
</div>
<div class="col-span-2">
- <p class="text-lg mb-2">Databases</p>
<MatchedDatabaseView
:project="project"
:environment-id="state.environment?.name || ''"
@@ -139,9 +145,9 @@ import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
import SchemaGroupTable from "@/components/DatabaseGroup/SchemaGroupTable.vue";
import { ResourceType } from "@/components/DatabaseGroup/common/ExprEditor/context";
-import dayjs from "dayjs";
import { useRouter } from "vue-router";
import { ComposedDatabaseGroup } from "@/types";
+import { generateIssueRoute } from "@/utils/databaseGroup/issue";
interface LocalState {
isLoaded: boolean;
@@ -218,39 +224,11 @@ const handleEditSchemaGroup = (schemaGroup: SchemaGroup) => {
editState.showConfigurePanel = true;
};
-const createMigration = async (
+const createMigration = (
type: "bb.issue.database.schema.update" | "bb.issue.database.data.update"
) => {
- const issueNameParts: string[] = [];
- issueNameParts.push(`[${databaseGroup.value.databaseGroupName}]`);
- issueNameParts.push(
- type === "bb.issue.database.schema.update" ? `Alter schema` : `Change data`
- );
- const datetime = dayjs().format("@MM-DD HH:mm");
- const tz = "UTC" + dayjs().format("ZZ");
- issueNameParts.push(`${datetime} ${tz}`);
- const schemaGroupList =
- await dbGroupStore.getOrFetchSchemaGroupListByDBGroupName(
- databaseGroup.value.name
- );
-
- const query: Record<string, any> = {
- template: type,
- mode: "tenant",
- name: issueNameParts.join(" "),
- project: project.value.uid,
- databaseGroupName: databaseGroup.value.name,
- // TODO(steven): support select schema group.
- schemaGroupNames: schemaGroupList.map((s) => s.name).join(","),
- };
-
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query,
- });
+ const issueRoute = generateIssueRoute(type, databaseGroup.value);
+ router.push(issueRoute);
};
watch(
diff --git a/frontend/src/views/SchemaGroupDetail.vue b/frontend/src/views/SchemaGroupDetail.vue
index da36feb4f1..9beb4d49b9 100644
--- a/frontend/src/views/SchemaGroupDetail.vue
+++ b/frontend/src/views/SchemaGroupDetail.vue
@@ -46,6 +46,20 @@
>
Configure
</button>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="createMigration('bb.issue.database.schema.update')"
+ >
+ Alter Schema
+ </button>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="createMigration('bb.issue.database.data.update')"
+ >
+ Change Data
+ </button>
</div>
</div>
@@ -95,6 +109,8 @@ import { ConditionGroupExpr } from "@/plugins/cel";
import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
import MatchedTableView from "@/components/DatabaseGroup/MatchedTableView.vue";
+import { generateIssueRoute } from "@/utils/databaseGroup/issue";
+import { useRouter } from "vue-router";
interface LocalState {
isLoaded: boolean;
@@ -117,6 +133,7 @@ const props = defineProps({
},
});
+const router = useRouter();
const projectStore = useProjectV1Store();
const dbGroupStore = useDBGroupStore();
const state = reactive<LocalState>({
@@ -134,6 +151,18 @@ const schemaGroup = computed(() => {
);
});
+const createMigration = (
+ type: "bb.issue.database.schema.update" | "bb.issue.database.data.update"
+) => {
+ if (!schemaGroup.value) {
+ return;
+ }
+ const issueRoute = generateIssueRoute(type, schemaGroup.value.databaseGroup, [
+ schemaGroup.value.name,
+ ]);
+ router.push(issueRoute);
+};
+
watch(
() => [props, schemaGroup.value],
async () => {