Skip to content

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

feat: add `ReadReplicaConnection` feature (#2899)

boojack4a34ae2d05ad
diff --git a/api/plan.go b/api/plan.go
index 7825b92a29..5325ed83ab 100644
--- a/api/plan.go
+++ b/api/plan.go
@@ -112,6 +112,10 @@ const (
// Currently, we only support GitLab EE/CE auth.
Feature3rdPartyAuth FeatureType = "bb.feature.3rd-party-auth"
+ // FeatureReadReplicaConnection allows user to set a read replica connection
+ // including host and port to data source.
+ FeatureReadReplicaConnection FeatureType = "bb.feature.read-replica-connection"
+
// Branding.
// FeatureBranding enables customized branding.
@@ -151,6 +155,8 @@ func (e FeatureType) Name() string {
return "RBAC"
case Feature3rdPartyAuth:
return "3rd party auth"
+ case FeatureReadReplicaConnection:
+ return "Read replica connection"
case FeatureBranding:
return "Branding"
case FeatureEnvironmentTierPolicy:
@@ -192,6 +198,7 @@ var FeatureMatrix = map[FeatureType][3]bool{
FeatureSQLReviewPolicy: {false, true, true},
FeatureRBAC: {false, true, true},
Feature3rdPartyAuth: {false, true, true},
+ FeatureReadReplicaConnection: {false, false, true},
FeatureBranding: {false, false, true},
FeatureEnvironmentTierPolicy: {false, false, true},
}
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 89d2b31f71..13dac0d033 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -347,6 +347,12 @@
</div>
</div>
</div>
+
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.read-replica-connection"
+ @cancel="state.showFeatureModal = false"
+ />
</template>
<script lang="ts" setup>
@@ -370,6 +376,7 @@ import {
import isEmpty from "lodash-es/isEmpty";
import { useI18n } from "vue-i18n";
import {
+ hasFeature,
pushNotification,
useCurrentUser,
useDatabaseStore,
@@ -389,6 +396,7 @@ interface State {
isUpdating: boolean;
dataSourceList: EditDataSource[];
currentDataSourceType: DataSourceType;
+ showFeatureModal: boolean;
}
const props = defineProps({
@@ -420,6 +428,7 @@ const state = reactive<State>({
isUpdating: false,
dataSourceList: dataSourceList,
currentDataSourceType: "ADMIN",
+ showFeatureModal: false,
});
const allowEdit = computed(() => {
@@ -588,6 +597,14 @@ const updateInstanceDataSource = () => {
portOverride: curr.portOverride,
};
+ if (!hasFeature("bb.feature.read-replica-connection")) {
+ if (newValue.hostOverride !== "" || newValue.portOverride !== "") {
+ currentDataSource.value.hostOverride = "";
+ currentDataSource.value.portOverride = "";
+ state.showFeatureModal = true;
+ }
+ }
+
if (curr.useEmptyPassword) {
// When 'Password: Empty' is checked, we set the password to empty string.
newValue.password = "";
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index bb210ec02f..ed69871edf 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1410,6 +1410,10 @@
"bb-feature-sync-schema": {
"title": "Synchronize Schema",
"desc": "Synchronize schema from the base database to the target database with the selected migration version."
+ },
+ "bb-feature-read-replica-connection": {
+ "title": "Read replica connection",
+ "desc": "Connect to a read replica for the read-only data source."
}
}
},
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 76f3f23063..00a6f45405 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1410,6 +1410,10 @@
"bb-feature-sync-schema": {
"title": "库表同步",
"desc": "将选定的源数据库 Schema 版本同步到目标数据库。请通过@:{'subscription.upgrade'}来完全开启该功能。"
+ },
+ "bb-feature-read-replica-connection": {
+ "title": "Read replica connection",
+ "desc": "使用只读副本连接到只读数据源。"
}
}
},
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index fc49a1d009..12333cbb07 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -22,6 +22,7 @@ export type FeatureType =
// Admin & Security
| "bb.feature.rbac"
| "bb.feature.3rd-party-auth"
+ | "bb.feature.read-replica-connection"
// Branding
| "bb.feature.branding";
@@ -90,6 +91,7 @@ export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([
// Admin & Security
["bb.feature.rbac", [false, true, true]],
["bb.feature.3rd-party-auth", [false, true, true]],
+ ["bb.feature.read-replica-connection", [false, false, true]],
// Branding
["bb.feature.branding", [false, false, true]],
]);
diff --git a/server/database.go b/server/database.go
index 9cf7e83448..094f549b59 100644
--- a/server/database.go
+++ b/server/database.go
@@ -677,6 +677,11 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, dataSourceCreate); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed create data source request").SetInternal(err)
}
+ if !s.feature(api.FeatureReadReplicaConnection) {
+ if dataSourceCreate.HostOverride != "" || dataSourceCreate.PortOverride != "" {
+ return echo.NewHTTPError(http.StatusForbidden, api.FeatureReadReplicaConnection.AccessErrorMessage())
+ }
+ }
if dataSourceCreate.Type == api.Admin && (dataSourceCreate.HostOverride != "" || dataSourceCreate.PortOverride != "") {
return echo.NewHTTPError(http.StatusBadRequest, "Host and port override cannot be set for admin type of data sources.")
@@ -748,6 +753,12 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, dataSourcePatch); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed patch data source request").SetInternal(err)
}
+ if !s.feature(api.FeatureReadReplicaConnection) {
+ // In the non-enterprise version, we should allow users to set HostOverride or PortOverride to the empty string.
+ if (dataSourcePatch.HostOverride != nil && *dataSourcePatch.HostOverride != "") || (dataSourcePatch.PortOverride != nil && *dataSourcePatch.PortOverride != "") {
+ return echo.NewHTTPError(http.StatusForbidden, api.FeatureReadReplicaConnection.AccessErrorMessage())
+ }
+ }
dataSourcePatch.ID = dataSourceID
dataSourcePatch.UpdaterID = c.Get(getPrincipalIDContextKey()).(int)