Skip to content

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

Use instance id and name to identify one and only one database (#65)

satoru3170af5e7425
diff --git a/frontend/src/components/IssueSidebar.vue b/frontend/src/components/IssueSidebar.vue
index fffc455909..941133f199 100644
--- a/frontend/src/components/IssueSidebar.vue
+++ b/frontend/src/components/IssueSidebar.vue
@@ -391,21 +391,19 @@ export default {
} else {
store
.dispatch(
- "database/fetchDatabaseListByInstanceID",
- props.instance.id
- )
- .then((list: Database[]) => {
- for (const database of list) {
- if (database.name == databaseName.value) {
- router.push({
- name: "workspace.database.detail",
- params: {
- databaseSlug: databaseSlug(database),
- },
- });
- break;
- }
+ "database/fetchDatabaseByInstanceIDAndName",
+ {
+ instanceID: props.instance.id,
+ name: databaseName.value,
}
+ )
+ .then((database: Database) => {
+ router.push({
+ name: "workspace.database.detail",
+ params: {
+ databaseSlug: databaseSlug(database),
+ },
+ });
});
}
};
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 5a76a4c1dd..308b4ce322 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -246,6 +246,18 @@ const actions = {
return databaseList;
},
+ async fetchDatabaseByInstanceIDAndName(
+ { commit, rootGetters }: any,
+ {
+ instanceID,
+ name,
+ }: {instanceID: InstanceID, name: string}
+ ) {
+ const data = (await axios.get(`/api/database?instance=${instanceID}&name=${name}`)).data;
+ const database = data.data[0];
+ return convert(database, data.included, rootGetters);
+ },
+
async fetchDatabaseListByProjectID(
{ commit, rootGetters }: any,
projectID: ProjectID
diff --git a/server/database.go b/server/database.go
index caf1c0855e..a688da1082 100644
--- a/server/database.go
+++ b/server/database.go
@@ -51,7 +51,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
g.GET("/database", func(c echo.Context) error {
ctx := context.Background()
- databaseFind := &api.DatabaseFind{}
+ databaseFind := new(api.DatabaseFind)
if instanceIDStr := c.QueryParam("instance"); instanceIDStr != "" {
instanceID, err := strconv.Atoi(instanceIDStr)
if err != nil {
@@ -59,6 +59,9 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
databaseFind.InstanceID = &instanceID
}
+ if name := c.QueryParam("name"); name != "" {
+ databaseFind.Name = &name
+ }
projectIDStr := c.QueryParams().Get("project")
if projectIDStr != "" {
projectID, err := strconv.Atoi(projectIDStr)
@@ -72,7 +75,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch database list").SetInternal(err)
}
- filteredList := []*api.Database{}
+ var filteredList []*api.Database
role := c.Get(GetRoleContextKey()).(api.Role)
// If caller is NOT requesting for a particular project and is NOT requesting for a paritcular
// instance or the caller is a Developer, then we will only return databases belonging to the