MCPcopy Create free account
hub / github.com/bytebase/bytebase / getDatabaseGroupByName

Function getDatabaseGroupByName

backend/api/v1/database_group_service.go:259–286  ·  view source on GitHub ↗
(ctx context.Context, stores *store.Store, databaseGroupName string, view v1pb.DatabaseGroupView)

Source from the content-addressed store, hash-verified

257}
258
259func getDatabaseGroupByName(ctx context.Context, stores *store.Store, databaseGroupName string, view v1pb.DatabaseGroupView) (*v1pb.DatabaseGroup, error) {
260 projectResourceID, databaseGroupResourceID, err := common.GetProjectIDDatabaseGroupID(databaseGroupName)
261 if err != nil {
262 return nil, connect.NewError(connect.CodeInvalidArgument, err)
263 }
264
265 project, err := stores.GetProject(ctx, &store.FindProjectMessage{
266 Workspace: common.GetWorkspaceIDFromContext(ctx),
267 ResourceID: &projectResourceID,
268 })
269 if err != nil {
270 return nil, connect.NewError(connect.CodeInternal, err)
271 }
272 if project == nil {
273 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project %q not found", projectResourceID))
274 }
275 databaseGroup, err := stores.GetDatabaseGroup(ctx, &store.FindDatabaseGroupMessage{
276 ProjectIDs: []string{project.ResourceID},
277 ResourceID: &databaseGroupResourceID,
278 })
279 if err != nil {
280 return nil, connect.NewError(connect.CodeInternal, err)
281 }
282 if databaseGroup == nil {
283 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("database group %q not found", databaseGroupResourceID))
284 }
285 return convertStoreToV1DatabaseGroupWithView(ctx, stores, databaseGroup, projectResourceID, view)
286}
287
288func convertStoreToV1DatabaseGroupWithView(ctx context.Context, stores *store.Store, databaseGroup *store.DatabaseGroupMessage, projectResourceID string, view v1pb.DatabaseGroupView) (*v1pb.DatabaseGroup, error) {
289 var allProjectDatabases []*store.DatabaseMessage

Callers 4

GetDatabaseGroupMethod · 0.85
RunPlanChecksMethod · 0.85
validateSpecsFunction · 0.85

Calls 6

ErrorfMethod · 0.80
GetProjectMethod · 0.65
GetDatabaseGroupMethod · 0.65

Tested by

no test coverage detected