Skip to content

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

fix: don't return wildcard database in API (#881)

STEVEN8429891baaa9
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.ts
index d9b545d453..7df81e3077 100644
--- a/frontend/src/store/modules/dataSource.ts
+++ b/frontend/src/store/modules/dataSource.ts
@@ -10,7 +10,6 @@ import {
DataSourcePatch,
EMPTY_ID,
empty,
- UNKNOWN_ID,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -109,15 +108,6 @@ const actions = {
dataSource: createdDataSource,
});
- if (createdDataSource.databaseId !== UNKNOWN_ID) {
- // Refresh the corresponding database as it contains data source.
- dispatch(
- "database/fetchDatabaseById",
- { databaseId: createdDataSource.databaseId },
- { root: true }
- );
- }
-
return createdDataSource;
},
@@ -151,11 +141,6 @@ const actions = {
dataSource: updatedDataSource,
});
- if (databaseId !== UNKNOWN_ID) {
- // Refresh the corresponding database as it contains data source.
- dispatch("database/fetchDatabaseById", { databaseId }, { root: true });
- }
-
return updatedDataSource;
},
@@ -171,9 +156,6 @@ const actions = {
);
commit("deleteDataSourceById", dataSourceId);
-
- // Refresh the corresponding database as it contains data source.
- dispatch("database/fetchDatabaseById", { databaseId }, { root: true });
},
};
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 8bbec9b6b2..6799508d8b 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -136,8 +136,8 @@ function convert(
);
if (i != -1) {
dataSourceList[i] = rootGetters["dataSource/convert"](item);
- dataSourceList[i].instance = instance;
- dataSourceList[i].database = databaseWPartial;
+ dataSourceList[i].instanceId = instance.id;
+ dataSourceList[i].databaseId = databaseWPartial.id;
}
}
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index b8dbc8c266..a039433646 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -258,10 +258,11 @@ const hasDataSourceFeature = computed(() =>
store.getters["subscription/feature"]("bb.feature.data-source")
);
-const databaseList = computed(() => {
- const list = store.getters["database/databaseListByInstanceId"](
+const databaseList = computed<Database[]>(() => {
+ const list: Database[] = store.getters["database/databaseListByInstanceId"](
instance.value.id
);
+
if (isDBAOrOwner(currentUser.value.role)) {
return list;
}
@@ -278,6 +279,7 @@ const databaseList = computed(() => {
}
}
}
+
return filteredList;
});
diff --git a/server/database.go b/server/database.go
index 146bc472dc..f9c8877e24 100644
--- a/server/database.go
+++ b/server/database.go
@@ -153,6 +153,11 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
if database == nil {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database not found with ID %d", id))
}
+ // Wildcard(*) database is used to connect all database at instance level.
+ // Do not return it via `get database by id` API.
+ if database.Name == api.AllDatabaseName {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Database %d is a wildcard *", id))
+ }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := jsonapi.MarshalPayload(c.Response().Writer, database); err != nil {
@@ -939,7 +944,6 @@ func (s *Server) composeDatabaseByFind(ctx context.Context, find *api.DatabaseFi
if err != nil {
return nil, err
}
-
if databaseRaw == nil {
return nil, nil
}
@@ -1005,6 +1009,8 @@ func (s *Server) composeDatabaseRelationship(ctx context.Context, raw *api.Datab
db.SourceBackup = sourceBackup
}
+ // For now, only wildcard(*) database has data sources and we disallow it to be returned to the client.
+ // So we set this value to an empty array until we need to develop a data source for a non-wildcard database.
db.DataSourceList = []*api.DataSource{}
rowStatus := api.Normal
diff --git a/store/seed/test/10080__data_source.sql b/store/seed/test/10080__data_source.sql
index 0b56c3e497..b01490769f 100644
--- a/store/seed/test/10080__data_source.sql
+++ b/store/seed/test/10080__data_source.sql
@@ -241,7 +241,7 @@ VALUES
1,
1,
6010,
- 7028,
+ 7031,
'Admin data source',
'ADMIN',
'admin',