Skip to content

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

chore: early feature check for creating/editing RO datasource (#6308)

Liu Ji9615a136b9f2
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index 9f9fd2c9ef..83e941769d 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -631,7 +631,6 @@ import {
unknownEnvironment,
} from "@/types";
import {
- hasFeature,
pushNotification,
useCurrentUserV1,
useSettingV1Store,
@@ -641,6 +640,7 @@ import {
useInstanceV1Store,
useDatabaseStore,
useGracefulRequest,
+ featureToRef,
} from "@/store";
import { getErrorCode, extractGrpcErrorMessage } from "@/utils/grpcweb";
import EnvironmentSelect from "@/components/EnvironmentSelect.vue";
@@ -713,6 +713,10 @@ const state = reactive<LocalState>({
createInstanceWarning: "",
});
+const hasReadonlyReplicaFeature = featureToRef(
+ "bb.feature.read-replica-connection"
+);
+
const extractBasicInfo = (instance: Instance | undefined): BasicInfo => {
return {
uid: instance?.uid ?? String(UNKNOWN_ID),
@@ -1053,7 +1057,7 @@ const handleMongodbConnectionStringSchemaChange = (event: Event) => {
const handleCurrentDataSourceHostInput = (event: Event) => {
if (currentDataSource.value.type === DataSourceType.READ_ONLY) {
- if (!hasFeature("bb.feature.read-replica-connection")) {
+ if (!hasReadonlyReplicaFeature.value) {
if (currentDataSource.value.host || currentDataSource.value.port) {
currentDataSource.value.host = adminDataSource.value.host;
currentDataSource.value.port = adminDataSource.value.port;
@@ -1068,7 +1072,7 @@ const handleCurrentDataSourceHostInput = (event: Event) => {
const handleCurrentDataSourcePortInput = (event: Event) => {
if (currentDataSource.value.type === DataSourceType.READ_ONLY) {
- if (!hasFeature("bb.feature.read-replica-connection")) {
+ if (!hasReadonlyReplicaFeature.value) {
if (currentDataSource.value.host || currentDataSource.value.port) {
currentDataSource.value.host = adminDataSource.value.host;
currentDataSource.value.port = adminDataSource.value.port;
@@ -1277,6 +1281,11 @@ const doUpdate = async () => {
return;
}
+ if (!checkRODataSourceFeature(instance)) {
+ state.showFeatureModal = true;
+ return;
+ }
+
// When clicking **Update** we may have more than one thing to do (if needed)
// 1. Patch the instance itself.
// 2. Update the admin datasource.
@@ -1553,4 +1562,41 @@ const extractDataSourceFromEdit = (
return ds;
};
+
+const checkRODataSourceFeature = (instance: Instance) => {
+ // Early pass if the feature is available.
+ if (hasReadonlyReplicaFeature.value) {
+ return true;
+ }
+
+ // Not editing/creating
+ if (!readonlyDataSource.value) {
+ return true;
+ }
+
+ if (readonlyDataSource.value.pendingCreate) {
+ // pre-flight feature guard check for creating RO datasource
+ return false;
+ } else {
+ // pre-flight feature guard check for updating RO datasource
+ const editing = extractDataSourceFromEdit(
+ instance,
+ readonlyDataSource.value
+ );
+ const original = instance.dataSources.find(
+ (ds) => ds.type === DataSourceType.READ_ONLY
+ );
+ if (original) {
+ const updateMask = calcDataSourceUpdateMask(
+ editing,
+ original,
+ readonlyDataSource.value
+ );
+ if (updateMask.length > 0) {
+ return false;
+ }
+ }
+ }
+ return true;
+};
</script>