Skip to content

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

chore: add sharding feature (#6397)

boojack8f8284e0e154
diff --git a/backend/legacyapi/plan.go b/backend/legacyapi/plan.go
index 4555e91918..e310eefc32 100644
--- a/backend/legacyapi/plan.go
+++ b/backend/legacyapi/plan.go
@@ -122,6 +122,8 @@ const (
FeatureTaskScheduleTime FeatureType = "bb.feature.task-schedule-time"
// FeatureEncryptedSecrets is a feature that allows user to setting the encrypted secrets for the database.
FeatureEncryptedSecrets FeatureType = "bb.feature.encrypted-secrets"
+ // FeatureSharding allows user to create database/schema groups.
+ FeatureSharding FeatureType = "bb.feature.sharding"
// VCS Integration.
@@ -223,6 +225,8 @@ func (e FeatureType) Name() string {
return "Task schedule time"
case FeatureEncryptedSecrets:
return "Encrypted secrets"
+ case FeatureSharding:
+ return "Sharding"
// VCS Integration
case FeatureVCSSchemaWriteBack:
return "Schema write-back"
@@ -305,6 +309,7 @@ var FeatureMatrix = map[FeatureType][3]bool{
FeatureSQLReview: {true, true, true},
FeatureTaskScheduleTime: {false, true, true},
FeatureEncryptedSecrets: {false, true, true},
+ FeatureSharding: {false, false, true},
// VCS Integration
FeatureVCSSchemaWriteBack: {false, true, true},
FeatureVCSSheetSync: {false, true, true},
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 57c8c84196..c4981a96f5 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -42,11 +42,12 @@
:checked="state.databaseSelectedTab === 'DATABASE_GROUP'"
value="DATABASE_GROUP"
name="database-tab"
- @update:checked="
- state.databaseSelectedTab = 'DATABASE_GROUP'
- "
+ @update:checked="handleDatabaseGroupTabSelect"
>
- Database group
+ <div class="flex flex-row items-center">
+ <span class="mr-1">Database group</span>
+ <FeatureBadge feature="bb.feature.sharding" />
+ </div>
</NRadio>
</div>
<div
@@ -175,9 +176,12 @@
:checked="state.databaseSelectedTab === 'DATABASE_GROUP'"
value="DATABASE_GROUP"
name="database-tab"
- @update:checked="state.databaseSelectedTab = 'DATABASE_GROUP'"
+ @update:checked="handleDatabaseGroupTabSelect"
>
- Database group
+ <div class="flex flex-row items-center">
+ <span class="mr-1">Database group</span>
+ <FeatureBadge feature="bb.feature.sharding" />
+ </div>
</NRadio>
</div>
<aside class="flex justify-end">
@@ -279,9 +283,9 @@
</div>
<FeatureModal
- v-if="state.showFeatureModal"
- feature="bb.feature.multi-tenancy"
- @cancel="state.showFeatureModal = false"
+ v-if="featureModalContext.feature"
+ :feature="featureModalContext.feature"
+ @cancel="featureModalContext.feature = undefined"
/>
<GhostDialog ref="ghostDialog" />
@@ -302,7 +306,12 @@ import { NTabs, NTabPane, NRadio } from "naive-ui";
import { computed, reactive, PropType, ref } from "vue";
import { useRouter } from "vue-router";
-import { ComposedDatabase, ComposedDatabaseGroup, UNKNOWN_ID } from "@/types";
+import {
+ ComposedDatabase,
+ ComposedDatabaseGroup,
+ FeatureType,
+ UNKNOWN_ID,
+} from "@/types";
import {
allowGhostMigrationV1,
allowUsingSchemaEditorV1,
@@ -342,7 +351,6 @@ type LocalState = ProjectStandardViewState &
databaseSelectedTab: "DATABASE" | "DATABASE_GROUP";
showSchemaLessDatabaseList: boolean;
showSchemaEditorModal: boolean;
- showFeatureModal: boolean;
selectedDatabaseGroupName?: string;
selectedSchemaGroupNameList?: string[];
};
@@ -369,6 +377,10 @@ const projectV1Store = useProjectV1Store();
const databaseV1Store = useDatabaseV1Store();
const dbGroupStore = useDBGroupStore();
+const featureModalContext = ref<{
+ feature?: FeatureType;
+}>({});
+
const ghostDialog = ref<InstanceType<typeof GhostDialog>>();
const schemaEditorContext = ref<{
databaseIdList: string[];
@@ -395,7 +407,6 @@ const state = reactive<LocalState>({
databaseSelectedTab: "DATABASE",
showSchemaLessDatabaseList: false,
showSchemaEditorModal: false,
- showFeatureModal: false,
});
// Returns true if alter schema, false if change data.
@@ -677,6 +688,15 @@ const toggleDatabaseSelection = (database: ComposedDatabase, on: boolean) => {
}
};
+const handleDatabaseGroupTabSelect = () => {
+ if (!hasFeature("bb.feature.sharding")) {
+ state.databaseSelectedTab = "DATABASE";
+ featureModalContext.value.feature = "bb.feature.sharding";
+ return;
+ }
+ state.databaseSelectedTab = "DATABASE_GROUP";
+};
+
const generateTenant = async () => {
if (state.selectedDatabaseGroupName) {
const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
@@ -692,7 +712,7 @@ const generateTenant = async () => {
}
if (!hasFeature("bb.feature.multi-tenancy")) {
- state.showFeatureModal = true;
+ featureModalContext.value.feature = "bb.feature.multi-tenancy";
return;
}
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 3dd8e351aa..2a4d593162 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -3,7 +3,10 @@
<div class="w-full flex flex-row justify-between items-center">
<span>Database groups</span>
<div class="flex flex-row gap-x-2">
- <NButton @click="handleCreateDatabaseGroup">New database group</NButton>
+ <NButton @click="handleCreateDatabaseGroup">
+ <span class="mr-1">New database group</span>
+ <FeatureBadge feature="bb.feature.sharding" />
+ </NButton>
</div>
</div>
<div class="mt-4">
@@ -22,19 +25,27 @@
:database-group="state.editingDatabaseGroup"
@close="state.showDatabaseGroupPanel = false"
/>
+
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.sharding"
+ @cancel="state.showFeatureModal = false"
+ />
</template>
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
import { computed, onMounted, reactive } from "vue";
-import { useDBGroupStore } from "@/store";
+import { hasFeature, useDBGroupStore } from "@/store";
import { ComposedProject } from "@/types";
import DatabaseGroupTable from "./DatabaseGroupTable.vue";
import DatabaseGroupPanel from "./DatabaseGroupPanel.vue";
import { DatabaseGroup } from "@/types/proto/v1/project_service";
import { ResourceType } from "./common/ExprEditor/context";
+import FeatureBadge from "../FeatureBadge.vue";
interface LocalState {
+ showFeatureModal: boolean;
showDatabaseGroupPanel: boolean;
resourceType: ResourceType;
editingDatabaseGroup?: DatabaseGroup;
@@ -46,6 +57,7 @@ const props = defineProps<{
const dbGroupStore = useDBGroupStore();
const state = reactive<LocalState>({
+ showFeatureModal: false,
showDatabaseGroupPanel: false,
resourceType: "DATABASE_GROUP",
});
@@ -59,6 +71,11 @@ onMounted(async () => {
});
const handleCreateDatabaseGroup = () => {
+ if (!hasFeature("bb.feature.sharding")) {
+ state.showFeatureModal = true;
+ return;
+ }
+
state.resourceType = "DATABASE_GROUP";
state.editingDatabaseGroup = undefined;
state.showDatabaseGroupPanel = true;
diff --git a/frontend/src/components/FeatureBadge.vue b/frontend/src/components/FeatureBadge.vue
index 8f36992421..84d83d6e99 100644
--- a/frontend/src/components/FeatureBadge.vue
+++ b/frontend/src/components/FeatureBadge.vue
@@ -5,7 +5,7 @@
exact-active-class=""
@click.prevent="noop"
>
- <heroicons-solid:sparkles class="w-5 h-5" />
+ <heroicons-solid:sparkles class="text-accent w-5 h-5" />
</router-link>
</template>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 26a96d7ea3..1c240e987d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2007,6 +2007,10 @@
"title": "Encrypted Secrets",
"desc": "Store your secrets of database and use them in your issue SQL scripts."
},
+ "bb-feature-sharding": {
+ "title": "Database/schema group",
+ "desc": "Easy to manage database/table sharding with database groups."
+ },
"bb-feature-disallow-signup": {
"title": "Disable self-service signup",
"desc": "Once disabled, users cannot self-service signup and can only be invited by the workspace owner."
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index 06ccfefa17..c4c6297d8b 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -29,6 +29,7 @@ export type FeatureType =
| "bb.feature.sql-review"
| "bb.feature.task-schedule-time"
| "bb.feature.encrypted-secrets"
+ | "bb.feature.sharding"
// VCS Integration
| "bb.feature.vcs-schema-write-back"
| "bb.feature.vcs-sheet-sync"