Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: decouple api/service/store packages for Environment (#962)
Yilong Lif010ac4e3ccb
diff --git a/api/environment.go b/api/environment.goindex 9fc2f86cc1..d96703036d 100644--- a/api/environment.go+++ b/api/environment.go@@ -1,44 +1,9 @@package apiimport (- "context""encoding/json")-// EnvironmentRaw is the store model for an Environment.-// Fields have exactly the same meanings as Environment.-type EnvironmentRaw struct {- ID int-- // Standard fields- RowStatus RowStatus- CreatorID int- CreatedTs int64- UpdaterID int- UpdatedTs int64-- // Domain specific fields- Name string- Order int-}--// ToEnvironment creates an instance of Environment based on the EnvironmentRaw.-// This is intended to be called when we need to compose an Environment relationship.-func (raw *EnvironmentRaw) ToEnvironment() *Environment {- return &Environment{- ID: raw.ID,-- RowStatus: raw.RowStatus,- CreatorID: raw.CreatorID,- CreatedTs: raw.CreatedTs,- UpdaterID: raw.UpdaterID,- UpdatedTs: raw.UpdatedTs,-- Name: raw.Name,- Order: raw.Order,- }-}-// Environment is the API message for an environment.type Environment struct {ID int `jsonapi:"primary,environment"`@@ -105,11 +70,3 @@ type EnvironmentDelete struct {// Value is assigned from the jwt subject field passed by the client.DeleterID int}--// EnvironmentService is the service for environments.-type EnvironmentService interface {- CreateEnvironment(ctx context.Context, create *EnvironmentCreate) (*EnvironmentRaw, error)- FindEnvironmentList(ctx context.Context, find *EnvironmentFind) ([]*EnvironmentRaw, error)- FindEnvironment(ctx context.Context, find *EnvironmentFind) (*EnvironmentRaw, error)- PatchEnvironment(ctx context.Context, patch *EnvironmentPatch) (*EnvironmentRaw, error)-}diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.goindex f074ad49a4..a58da87002 100644--- a/bin/server/cmd/root.go+++ b/bin/server/cmd/root.go@@ -383,7 +383,6 @@ func (m *Main) Run(ctx context.Context) error {s.ProjectService = store.NewProjectService(m.l, db, cacheService)s.ProjectMemberService = store.NewProjectMemberService(m.l, db)s.ProjectWebhookService = store.NewProjectWebhookService(m.l, db)- s.EnvironmentService = store.NewEnvironmentService(m.l, db, cacheService)s.DataSourceService = store.NewDataSourceService(m.l, db, cacheService)s.BackupService = store.NewBackupService(m.l, db, s.PolicyService)s.DatabaseService = store.NewDatabaseService(m.l, db, cacheService, s.PolicyService, s.BackupService)diff --git a/server/anomaly_scanner.go b/server/anomaly_scanner.goindex 372e89efde..b28fdfc867 100644--- a/server/anomaly_scanner.go+++ b/server/anomaly_scanner.go@@ -58,26 +58,12 @@ func (s *AnomalyScanner) Run(ctx context.Context, wg *sync.WaitGroup) {ctx := context.Background()- envFind := &api.EnvironmentFind{}- envRawList, err := s.server.EnvironmentService.FindEnvironmentList(ctx, envFind)+ envList, err := s.server.store.FindEnvironment(ctx, &api.EnvironmentFind{})if err != nil {s.l.Error("Failed to retrieve instance list", zap.Error(err))return}- // compose environments- var envList []*api.Environment- for _, envRaw := range envRawList {- env, err := s.server.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- s.l.Error("Failed to compose environment relationship",- zap.String("environment", envRaw.Name),- zap.Error(err))- return- }- envList = append(envList, env)- }-backupPlanPolicyMap := make(map[int]*api.BackupPlanPolicy)for _, env := range envList {policy, err := s.server.PolicyService.GetBackupPlanPolicy(ctx, env.ID)diff --git a/server/environment.go b/server/environment.goindex 2cc7455888..63ce9258b4 100644--- a/server/environment.go+++ b/server/environment.go@@ -24,7 +24,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {envCreate.CreatorID = c.Get(getPrincipalIDContextKey()).(int)- envRaw, err := s.EnvironmentService.CreateEnvironment(ctx, envCreate)+ env, err := s.store.CreateEnvironment(ctx, envCreate)if err != nil {if common.ErrorCode(err) == common.Conflict {return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Environment name already exists: %s", envCreate.Name))@@ -32,11 +32,6 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create environment").SetInternal(err)}- env, err := s.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch created environment relationship").SetInternal(err)- }-c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, env); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create environment response").SetInternal(err)@@ -51,20 +46,11 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {rowStatus := api.RowStatus(rowStatusStr)envFind.RowStatus = &rowStatus}- envRawList, err := s.EnvironmentService.FindEnvironmentList(ctx, envFind)+ envList, err := s.store.FindEnvironment(ctx, envFind)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environment list").SetInternal(err)}- var envList []*api.Environment- for _, envRaw := range envRawList {- env, err := s.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch environment relationship: %v", envRaw.Name)).SetInternal(err)- }- envList = append(envList, env)- }-c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, envList); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal environment list response").SetInternal(err)@@ -87,7 +73,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch environment request").SetInternal(err)}- envRaw, err := s.EnvironmentService.PatchEnvironment(ctx, envPatch)+ env, err := s.store.PatchEnvironment(ctx, envPatch)if err != nil {if common.ErrorCode(err) == common.NotFound {return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", id))@@ -95,11 +81,6 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch environment ID: %v", id)).SetInternal(err)}- env, err := s.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch updated environment relationship: %v", envRaw.Name)).SetInternal(err)- }-c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, env); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal environment ID response: %v", id)).SetInternal(err)@@ -120,7 +101,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted environment reorder request").SetInternal(errors.New("Failed to convert request item to *api.EnvironmentPatch"))}envPatch.UpdaterID = c.Get(getPrincipalIDContextKey()).(int)- if _, err := s.EnvironmentService.PatchEnvironment(ctx, envPatch); err != nil {+ if _, err := s.store.PatchEnvironment(ctx, envPatch); err != nil {if common.ErrorCode(err) == common.NotFound {return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", envPatch.ID))}@@ -128,21 +109,11 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {}}- envFind := &api.EnvironmentFind{}- envRawList, err := s.EnvironmentService.FindEnvironmentList(ctx, envFind)+ envList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{})if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environment list for reorder").SetInternal(err)}- var envList []*api.Environment- for _, envRaw := range envRawList {- env, err := s.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch reordered environment relationship: %v", envRaw.Name)).SetInternal(err)- }- envList = append(envList, env)- }-c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, envList); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal environment reorder response").SetInternal(err)@@ -150,41 +121,3 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {return nil})}--func (s *Server) composeEnvironmentByID(ctx context.Context, id int) (*api.Environment, error) {- envFind := &api.EnvironmentFind{- ID: &id,- }- envRaw, err := s.EnvironmentService.FindEnvironment(ctx, envFind)- if err != nil {- return nil, err- }- if envRaw == nil {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment not found with ID %v", id)}- }-- env, err := s.composeEnvironmentRelationship(ctx, envRaw)- if err != nil {- return nil, err- }-- return env, nil-}--func (s *Server) composeEnvironmentRelationship(ctx context.Context, raw *api.EnvironmentRaw) (*api.Environment, error) {- env := raw.ToEnvironment()-- creator, err := s.store.GetPrincipalByID(ctx, env.CreatorID)- if err != nil {- return nil, err- }- env.Creator = creator-- updater, err := s.store.GetPrincipalByID(ctx, env.UpdaterID)- if err != nil {- return nil, err- }- env.Updater = updater-- return env, nil-}diff --git a/server/instance.go b/server/instance.goindex 3ce7911443..bb00c36fdb 100644--- a/server/instance.go+++ b/server/instance.go@@ -459,7 +459,7 @@ func (s *Server) composeInstanceRelationship(ctx context.Context, raw *api.Insta}instance.Updater = updater- env, err := s.composeEnvironmentByID(ctx, instance.EnvironmentID)+ env, err := s.store.GetEnvironmentByID(ctx, instance.EnvironmentID)if err != nil {return nil, err}diff --git a/server/label.go b/server/label.goindex 3fd3319b04..df80ffe3f9 100644--- a/server/label.go+++ b/server/label.go@@ -32,7 +32,7 @@ func (s *Server) registerLabelRoutes(g *echo.Group) {}// Add reserved environment key.- envRawList, err := s.EnvironmentService.FindEnvironmentList(ctx, &api.EnvironmentFind{RowStatus: &rowStatus})+ envRawList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{RowStatus: &rowStatus})if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environments").SetInternal(err)}diff --git a/server/policy.go b/server/policy.goindex c77bad9260..2d107669db 100644--- a/server/policy.go+++ b/server/policy.go@@ -120,7 +120,7 @@ func (s *Server) composePolicyRelationship(ctx context.Context, raw *api.PolicyR}policy.Updater = updater- env, err := s.composeEnvironmentByID(ctx, policy.EnvironmentID)+ env, err := s.store.GetEnvironmentByID(ctx, policy.EnvironmentID)if err != nil {return nil, err}diff --git a/server/server.go b/server/server.goindex c1c3b864cb..b0ef5c5149 100644--- a/server/server.go+++ b/server/server.go@@ -41,7 +41,6 @@ type Server struct {ProjectService api.ProjectServiceProjectMemberService api.ProjectMemberServiceProjectWebhookService api.ProjectWebhookService- EnvironmentService api.EnvironmentServiceInstanceService api.InstanceServiceInstanceUserService api.InstanceUserServiceDatabaseService api.DatabaseServicediff --git a/server/stage.go b/server/stage.goindex 5b56f5b3ee..7b84e666c2 100644--- a/server/stage.go+++ b/server/stage.go@@ -42,7 +42,7 @@ func (s *Server) composeStageRelationship(ctx context.Context, raw *api.StageRaw}stage.Updater = updater- env, err := s.composeEnvironmentByID(ctx, stage.EnvironmentID)+ env, err := s.store.GetEnvironmentByID(ctx, stage.EnvironmentID)if err != nil {return nil, err}@@ -70,7 +70,7 @@ func (s *Server) composeStageRelationshipValidateOnly(ctx context.Context, stagereturn err}- stage.Environment, err = s.composeEnvironmentByID(ctx, stage.EnvironmentID)+ stage.Environment, err = s.store.GetEnvironmentByID(ctx, stage.EnvironmentID)if err != nil {return err}diff --git a/store/environment.go b/store/environment.goindex 840caeb83c..578067c150 100644--- a/store/environment.go+++ b/store/environment.go@@ -8,35 +8,134 @@ import ("github.com/bytebase/bytebase/api""github.com/bytebase/bytebase/common"- "go.uber.org/zap")-var (- _ api.EnvironmentService = (*EnvironmentService)(nil)-)+// environmentRaw is the store model for an Environment.+// Fields have exactly the same meanings as Environment.+type environmentRaw struct {+ ID int++ // Standard fields+ RowStatus api.RowStatus+ CreatorID int+ CreatedTs int64+ UpdaterID int+ UpdatedTs int64++ // Domain specific fields+ Name string+ Order int+}++// toEnvironment creates an instance of Environment based on the EnvironmentRaw.+// This is intended to be called when we need to compose an Environment relationship.+func (raw *environmentRaw) toEnvironment() *api.Environment {+ return &api.Environment{+ ID: raw.ID,++ RowStatus: raw.RowStatus,+ CreatorID: raw.CreatorID,+ CreatedTs: raw.CreatedTs,+ UpdaterID: raw.UpdaterID,+ UpdatedTs: raw.UpdatedTs,++ Name: raw.Name,+ Order: raw.Order,+ }+}++// CreateEnvironment creates an instance of Environment+func (s *Store) CreateEnvironment(ctx context.Context, create *api.EnvironmentCreate) (*api.Environment, error) {+ EnvironmentRaw, err := s.createEnvironmentRaw(ctx, create)+ if err != nil {+ return nil, fmt.Errorf("Failed to create Environment with EnvironmentCreate[%+v], error[%w]", create, err)+ }+ Environment, err := s.composeEnvironment(ctx, EnvironmentRaw)+ if err != nil {+ return nil, fmt.Errorf("Failed to compose Environment with EnvironmentRaw[%+v], error[%w]", EnvironmentRaw, err)+ }+ return Environment, nil+}++// FindEnvironment finds a list of Environment instances+func (s *Store) FindEnvironment(ctx context.Context, find *api.EnvironmentFind) ([]*api.Environment, error) {+ EnvironmentRawList, err := s.findEnvironmentListRaw(ctx, find)+ if err != nil {+ return nil, fmt.Errorf("Failed to find Environment list, error[%w]", err)+ }+ var EnvironmentList []*api.Environment+ for _, raw := range EnvironmentRawList {+ Environment, err := s.composeEnvironment(ctx, raw)+ if err != nil {+ return nil, fmt.Errorf("Failed to compose Environment role with EnvironmentRaw[%+v], error[%w]", raw, err)+ }+ EnvironmentList = append(EnvironmentList, Environment)+ }+ return EnvironmentList, nil+}++// PatchEnvironment patches an instance of Environment+func (s *Store) PatchEnvironment(ctx context.Context, patch *api.EnvironmentPatch) (*api.Environment, error) {+ EnvironmentRaw, err := s.patchEnvironmentRaw(ctx, patch)+ if err != nil {+ return nil, fmt.Errorf("Failed to patch Environment with EnvironmentPatch[%+v], error[%w]", patch, err)+ }+ Environment, err := s.composeEnvironment(ctx, EnvironmentRaw)+ if err != nil {+ return nil, fmt.Errorf("Failed to compose Environment role with EnvironmentRaw[%+v], error[%w]", EnvironmentRaw, err)+ }+ return Environment, nil+}-// EnvironmentService represents a service for managing environment.-type EnvironmentService struct {- l *zap.Logger- db *DB+// GetEnvironmentByID gets an instance of Environment by ID+func (s *Store) GetEnvironmentByID(ctx context.Context, id int) (*api.Environment, error) {+ envRaw, err := s.getEnvironmentByIDRaw(ctx, id)+ if err != nil {+ return nil, err+ }+ if envRaw == nil {+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment not found with ID %v", id)}+ }- cache api.CacheService+ env, err := s.composeEnvironment(ctx, envRaw)+ if err != nil {+ return nil, err+ }++ return env, nil}-// NewEnvironmentService returns a new instance of EnvironmentService.-func NewEnvironmentService(logger *zap.Logger, db *DB, cache api.CacheService) *EnvironmentService {- return &EnvironmentService{l: logger, db: db, cache: cache}+//+// private functions+//++func (s *Store) composeEnvironment(ctx context.Context, raw *environmentRaw) (*api.Environment, error) {+ env := raw.toEnvironment()++ creator, err := s.GetPrincipalByID(ctx, env.CreatorID)+ if err != nil {+ return nil, err+ }+ env.Creator = creator++ updater, err := s.GetPrincipalByID(ctx, env.UpdaterID)+ if err != nil {+ return nil, err+ }+ env.Updater = updater++ return env, nil}-// CreateEnvironment creates a new environment.-func (s *EnvironmentService) CreateEnvironment(ctx context.Context, create *api.EnvironmentCreate) (*api.EnvironmentRaw, error) {+// createEnvironmentRaw creates a new environment.+func (s *Store) createEnvironmentRaw(ctx context.Context, create *api.EnvironmentCreate) (*environmentRaw, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, FormatError(err)}defer tx.PTx.Rollback()- environment, err := s.createEnvironment(ctx, tx.PTx, create)+ environment, err := s.createEnvironmentImpl(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -52,15 +151,15 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, create *api.return environment, nil}-// FindEnvironmentList retrieves a list of environments based on find.-func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.EnvironmentFind) ([]*api.EnvironmentRaw, error) {+// findEnvironmentListRaw retrieves a list of environments based on find.+func (s *Store) findEnvironmentListRaw(ctx context.Context, find *api.EnvironmentFind) ([]*environmentRaw, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, FormatError(err)}defer tx.PTx.Rollback()- list, err := s.findEnvironmentList(ctx, tx.PTx, find)+ list, err := s.findEnvironmentImpl(ctx, tx.PTx, find)if err != nil {return nil, err}@@ -76,18 +175,16 @@ func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.return list, nil}-// FindEnvironment retrieves a single environment based on find.+// getEnvironmentByIDRaw retrieves a single environment based on find.// Returns ECONFLICT if finding more than 1 matching records.-func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.EnvironmentFind) (*api.EnvironmentRaw, error) {- if find.ID != nil {- envRaw := &api.EnvironmentRaw{}- has, err := s.cache.FindCache(api.EnvironmentCache, *find.ID, envRaw)- if err != nil {- return nil, err- }- if has {- return envRaw, nil- }+func (s *Store) getEnvironmentByIDRaw(ctx context.Context, id int) (*environmentRaw, error) {+ envRaw := &environmentRaw{}+ has, err := s.cache.FindCache(api.EnvironmentCache, id, envRaw)+ if err != nil {+ return nil, err+ }+ if has {+ return envRaw, nil}tx, err := s.db.BeginTx(ctx, nil)@@ -96,13 +193,14 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi}defer tx.PTx.Rollback()- envRawList, err := s.findEnvironmentList(ctx, tx.PTx, find)+ find := &api.EnvironmentFind{ID: &id}+ envRawList, err := s.findEnvironmentImpl(ctx, tx.PTx, find)if err != nil {return nil, err}if len(envRawList) == 0 {- return nil, nil+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment not found with EnvironmentFind[%+v]", find)}} else if len(envRawList) > 1 {return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d environments with filter %+v, expect 1", len(envRawList), find)}}@@ -112,16 +210,16 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envireturn envRawList[0], nil}-// PatchEnvironment updates an existing environment by ID.+// patchEnvironmentRaw updates an existing environment by ID.// Returns ENOTFOUND if environment does not exist.-func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.EnvironmentPatch) (*api.EnvironmentRaw, error) {+func (s *Store) patchEnvironmentRaw(ctx context.Context, patch *api.EnvironmentPatch) (*environmentRaw, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, FormatError(err)}defer tx.PTx.Rollback()- envRaw, err := s.patchEnvironment(ctx, tx.PTx, patch)+ envRaw, err := s.patchEnvironmentImpl(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -137,8 +235,8 @@ func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.Enreturn envRaw, nil}-// createEnvironment creates a new environment.-func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*api.EnvironmentRaw, error) {+// createEnvironmentImpl creates a new environment.+func (s *Store) createEnvironmentImpl(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*environmentRaw, error) {// The order is the MAX(order) + 1row1, err1 := tx.QueryContext(ctx, `SELECT "order"@@ -187,7 +285,7 @@ func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *sql.Tx,defer row2.Close()row2.Next()- var envRaw api.EnvironmentRaw+ var envRaw environmentRawif err := row2.Scan(&envRaw.ID,&envRaw.RowStatus,@@ -205,7 +303,7 @@ func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *sql.Tx,return &envRaw, nil}-func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Tx, find *api.EnvironmentFind) ([]*api.EnvironmentRaw, error) {+func (s *Store) findEnvironmentImpl(ctx context.Context, tx *sql.Tx, find *api.EnvironmentFind) ([]*environmentRaw, error) {// Build WHERE clause.where, args := []string{"1 = 1"}, []interface{}{}if v := find.ID; v != nil {@@ -235,9 +333,9 @@ func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Txdefer rows.Close()// Iterate over result set and deserialize rows into list.- var envRawList []*api.EnvironmentRaw+ var envRawList []*environmentRawfor rows.Next() {- var environment api.EnvironmentRaw+ var environment environmentRawif err := rows.Scan(&environment.ID,&environment.RowStatus,@@ -260,8 +358,8 @@ func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Txreturn envRawList, nil}-// patchEnvironment updates a environment by ID. Returns the new state of the environment after update.-func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *sql.Tx, patch *api.EnvironmentPatch) (*api.EnvironmentRaw, error) {+// patchEnvironmentImpl updates a environment by ID. Returns the new state of the environment after update.+func (s *Store) patchEnvironmentImpl(ctx context.Context, tx *sql.Tx, patch *api.EnvironmentPatch) (*environmentRaw, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.RowStatus; v != nil {@@ -291,7 +389,7 @@ func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *sql.Tx, pdefer row.Close()if row.Next() {- var environment api.EnvironmentRaw+ var environment environmentRawif err := row.Scan(&environment.ID,&environment.RowStatus,diff --git a/store/member.go b/store/member.goindex db799e32c2..6498e4bf53 100644--- a/store/member.go+++ b/store/member.go@@ -63,7 +63,7 @@ func (s *Store) CreateMember(ctx context.Context, create *api.MemberCreate) (*ap// FindMemberList finds a list of Member instancesfunc (s *Store) FindMemberList(ctx context.Context, find *api.MemberFind) ([]*api.Member, error) {- memberRawList, err := s.findMemberRawList(ctx, find)+ memberRawList, err := s.findMemberListRaw(ctx, find)if err != nil {return nil, fmt.Errorf("Failed to find Member list, error[%w]", err)}@@ -132,15 +132,15 @@ func (s *Store) createMemberRaw(ctx context.Context, create *api.MemberCreate) (return member, nil}-// findMemberRawList retrieves a list of memberRaw instances.-func (s *Store) findMemberRawList(ctx context.Context, find *api.MemberFind) ([]*memberRaw, error) {+// findMemberListRaw retrieves a list of memberRaw instances.+func (s *Store) findMemberListRaw(ctx context.Context, find *api.MemberFind) ([]*memberRaw, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, FormatError(err)}defer tx.PTx.Rollback()- memberRawList, err := findMemberRawListImpl(ctx, tx.PTx, find)+ memberRawList, err := findMemberListImpl(ctx, tx.PTx, find)if err != nil {return nil, err}@@ -174,7 +174,7 @@ func (s *Store) findMemberRaw(ctx context.Context, find *api.MemberFind) (*membe}defer tx.PTx.Rollback()- list, err := findMemberRawListImpl(ctx, tx.PTx, find)+ list, err := findMemberListImpl(ctx, tx.PTx, find)if err != nil {return nil, err}@@ -285,7 +285,7 @@ func createMemberImpl(ctx context.Context, tx *sql.Tx, create *api.MemberCreate)return &memberRaw, nil}-func findMemberRawListImpl(ctx context.Context, tx *sql.Tx, find *api.MemberFind) ([]*memberRaw, error) {+func findMemberListImpl(ctx context.Context, tx *sql.Tx, find *api.MemberFind) ([]*memberRaw, error) {// Build WHERE clause.where, args := []string{"1 = 1"}, []interface{}{}if v := find.ID; v != nil {diff --git a/store/principal.go b/store/principal.goindex e10f96dbd3..a93563426b 100644--- a/store/principal.go+++ b/store/principal.go@@ -109,7 +109,7 @@ func (s *Store) PatchPrincipal(ctx context.Context, patch *api.PrincipalPatch) (return principal, nil}-// GetPrincipalByID gets a composesd instance of Principal by ID+// GetPrincipalByID gets an instance of Principal by IDfunc (s *Store) GetPrincipalByID(ctx context.Context, id int) (*api.Principal, error) {principalFind := &api.PrincipalFind{ID: &id,