Skip to content

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

chore: deprecate legacy code (#6697)

ecmadao85dbb96ccab4
diff --git a/backend/api/v1/anomaly_service.go b/backend/api/v1/anomaly_service.go
index 1e02de776a..cd4a7275c4 100644
--- a/backend/api/v1/anomaly_service.go
+++ b/backend/api/v1/anomaly_service.go
@@ -156,7 +156,9 @@ func (s *AnomalyService) convertToAnomaly(ctx context.Context, anomaly *store.An
if err := json.Unmarshal([]byte(anomaly.Payload), &detail); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal database backup policy violation anomaly payload")
}
- environment, err := s.store.GetEnvironmentByID(ctx, detail.EnvironmentID)
+ environment, err := s.store.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{
+ UID: &detail.EnvironmentID,
+ })
if err != nil {
return nil, errors.Wrapf(err, "failed to find environment with id %d", detail.EnvironmentID)
}
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 9681f95eb0..fdf7187af2 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -207,14 +207,6 @@ func (s *InstanceService) SyncSlowQueries(ctx context.Context, request *v1pb.Syn
return nil, status.Errorf(codes.InvalidArgument, "instance %q has been deleted", request.Instance)
}
- composedInstance, err := s.store.GetInstanceByID(ctx, instance.UID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, err.Error())
- }
- if composedInstance == nil {
- return nil, status.Errorf(codes.NotFound, "instance %q not found", request.Instance)
- }
-
slowQueryPolicy, err := s.store.GetSlowQueryPolicy(ctx, api.PolicyResourceTypeInstance, instance.UID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
@@ -235,7 +227,7 @@ func (s *InstanceService) SyncSlowQueries(ctx context.Context, request *v1pb.Syn
}
// Sync slow queries for instance.
- s.stateCfg.InstanceSlowQuerySyncChan <- composedInstance
+ s.stateCfg.InstanceSlowQuerySyncChan <- instance.ResourceID
case db.Postgres:
databases, err := s.store.ListDatabases(ctx, &store.FindDatabaseMessage{
InstanceID: &instance.ResourceID,
@@ -278,7 +270,7 @@ func (s *InstanceService) SyncSlowQueries(ctx context.Context, request *v1pb.Syn
}
// Sync slow queries for instance.
- s.stateCfg.InstanceSlowQuerySyncChan <- composedInstance
+ s.stateCfg.InstanceSlowQuerySyncChan <- instance.ResourceID
default:
return nil, status.Errorf(codes.InvalidArgument, "unsupported engine %q", instance.Engine)
}
diff --git a/backend/api/v1/logging_service.go b/backend/api/v1/logging_service.go
index 80ba68ed5c..9e199450cd 100644
--- a/backend/api/v1/logging_service.go
+++ b/backend/api/v1/logging_service.go
@@ -325,7 +325,9 @@ func (s *LoggingService) convertToLogEntity(ctx context.Context, activity *store
api.ActivityProjectMemberDelete,
api.ActivityProjectMemberRoleUpdate,
api.ActivityDatabaseRecoveryPITRDone:
- project, err := s.store.GetProjectByID(ctx, activity.ContainerUID)
+ project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{
+ UID: &activity.ContainerUID,
+ })
if err != nil {
return nil, err
}
@@ -336,7 +338,9 @@ func (s *LoggingService) convertToLogEntity(ctx context.Context, activity *store
case
api.ActivitySQLEditorQuery,
api.ActivitySQLExport:
- instance, err := s.store.GetInstanceByID(ctx, activity.ContainerUID)
+ instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{
+ UID: &activity.ContainerUID,
+ })
if err != nil {
return nil, err
}
diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.go
index 7634b66df7..ee4c86017d 100644
--- a/backend/api/v1/sheet_service.go
+++ b/backend/api/v1/sheet_service.go
@@ -831,7 +831,9 @@ func (s *SheetService) convertToAPISheetMessage(ctx context.Context, sheet *stor
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to get creator: %v", err))
}
- project, err := s.store.GetProjectByID(ctx, sheet.ProjectUID)
+ project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{
+ UID: &sheet.ProjectUID,
+ })
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to get project: %v", err))
}
diff --git a/backend/component/state/state.go b/backend/component/state/state.go
index 8a8882bd32..a57f08ef6d 100644
--- a/backend/component/state/state.go
+++ b/backend/component/state/state.go
@@ -4,7 +4,6 @@ package state
import (
"sync"
- api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
)
@@ -16,7 +15,7 @@ type State struct {
// InstanceDatabaseSyncChan is the channel for synchronizing schemas for instances.
InstanceDatabaseSyncChan chan *store.InstanceMessage
// InstanceSlowQuerySyncChan is the channel for synchronizing slow query logs for instances.
- InstanceSlowQuerySyncChan chan *api.Instance
+ InstanceSlowQuerySyncChan chan string
// RollbackGenerate is the set of tasks for generating rollback statements.
RollbackGenerate sync.Map // map[task.ID]*store.TaskMessage
diff --git a/backend/legacyapi/auth.go b/backend/legacyapi/auth.go
deleted file mode 100644
index a6a1fcd58e..0000000000
--- a/backend/legacyapi/auth.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package api
-
-import "github.com/bytebase/bytebase/backend/plugin/vcs"
-
-// AuthProvider is the authentication provider which only supports GitLab for now.
-type AuthProvider struct {
- ID int `jsonapi:"attr,id"`
- Type vcs.Type `jsonapi:"attr,type"`
- Name string `jsonapi:"attr,name"`
- InstanceURL string `jsonapi:"attr,instanceUrl"`
- ApplicationID string `jsonapi:"attr,applicationId"`
- // Secret will be used for OAuth on the client side when user choose to login via Gitlab
- Secret string `jsonapi:"attr,secret"`
-}
-
-// VCSLogin is the API message for logining via VCS.
-type VCSLogin struct {
- // VCSID is the ID of the chosen VCS role provider.
- VCSID int `jsonapi:"attr,vcsId"`
- // Name is the user configured name of the role provider.
- Name string `jsonapi:"attr,name"`
- // Code is the authentication code granted by GitLab server,
- // we will use this code to exchange the OAuth token.
- Code string `jsonapi:"attr,code"`
-}
-
-// Login is the API message for logins.
-type Login struct {
- // Domain specific fields
- Email string `jsonapi:"attr,email"`
- Password string `jsonapi:"attr,password"`
-}
-
-// SignUp is the API message for sign-ups.
-type SignUp struct {
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Email string `jsonapi:"attr,email"`
- Password string `jsonapi:"attr,password"`
-}
diff --git a/backend/legacyapi/v1/docs.go b/backend/legacyapi/v1/docs.go
deleted file mode 100644
index 480ebb893c..0000000000
--- a/backend/legacyapi/v1/docs.go
+++ /dev/null
@@ -1,2 +0,0 @@
-// Package v1 is the API message for OpenAPI in V1 version.
-package v1
diff --git a/backend/legacyapi/v1/instance.go b/backend/legacyapi/v1/instance.go
deleted file mode 100644
index 2914795a26..0000000000
--- a/backend/legacyapi/v1/instance.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package v1
-
-// InstanceDatabasePatch is the API message for patching an instance database.
-type InstanceDatabasePatch struct {
- // Project is the project resource ID.
- Project *string `json:"project"`
-}
diff --git a/backend/legacyapi/v1/issue.go b/backend/legacyapi/v1/issue.go
deleted file mode 100644
index 64048aadab..0000000000
--- a/backend/legacyapi/v1/issue.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package v1
-
-import (
- "github.com/bytebase/bytebase/backend/plugin/db"
-)
-
-// IssueCreate is the API message for creating an issue.
-type IssueCreate struct {
- // Related fields
- ProjectID string `json:"projectID"`
- Database string `json:"database"`
- Environment string `json:"environment"`
-
- // Domain specific fields
- Name string `json:"name"`
- Description string `json:"description"`
- MigrationType db.MigrationType `json:"migrationType"`
- Statement string `json:"statement"`
- SchemaVersion string `json:"schemaVersion"`
-}
diff --git a/backend/metric/collector/instance_count.go b/backend/metric/collector/instance_count.go
index c02ccaffa7..394b5b83c3 100644
--- a/backend/metric/collector/instance_count.go
+++ b/backend/metric/collector/instance_count.go
@@ -35,7 +35,9 @@ func (c *instanceCountCollector) Collect(ctx context.Context) ([]*metric.Metric,
}
for _, instanceCountMetric := range instanceCountMetricList {
- env, err := c.store.GetEnvironmentByID(ctx, instanceCountMetric.EnvironmentID)
+ env, err := c.store.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{
+ UID: &instanceCountMetric.EnvironmentID,
+ })
if err != nil {
log.Debug("failed to get environment by id", zap.Int("id", instanceCountMetric.EnvironmentID))
continue
@@ -46,7 +48,7 @@ func (c *instanceCountCollector) Collect(ctx context.Context) ([]*metric.Metric,
Value: instanceCountMetric.Count,
Labels: map[string]any{
"engine": string(instanceCountMetric.Engine),
- "environment": env.Name,
+ "environment": env.Title,
"status": string(instanceCountMetric.RowStatus),
},
})
diff --git a/backend/runner/slowquerysync/syncer.go b/backend/runner/slowquerysync/syncer.go
index 56fb865002..4aecf697cb 100644
--- a/backend/runner/slowquerysync/syncer.go
+++ b/backend/runner/slowquerysync/syncer.go
@@ -58,9 +58,9 @@ func (s *Syncer) Run(ctx context.Context, wg *sync.WaitGroup) {
case <-ctx.Done():
log.Debug("Slow query syncer received context cancellation")
return
- case instance := <-s.stateCfg.InstanceSlowQuerySyncChan:
- log.Debug("Slow query syncer received instance slow query sync request", zap.String("instance", instance.ResourceID))
- s.syncSlowQuery(ctx, instance)
+ case instanceResourceID := <-s.stateCfg.InstanceSlowQuerySyncChan:
+ log.Debug("Slow query syncer received instance slow query sync request", zap.String("instance", instanceResourceID))
+ s.syncSlowQuery(ctx, &instanceResourceID)
case <-ticker.C:
log.Debug("Slow query syncer received tick")
s.syncSlowQuery(ctx, nil)
@@ -68,7 +68,7 @@ func (s *Syncer) Run(ctx context.Context, wg *sync.WaitGroup) {
}
}
-func (s *Syncer) syncSlowQuery(ctx context.Context, instance *api.Instance) {
+func (s *Syncer) syncSlowQuery(ctx context.Context, instanceResourceID *string) {
defer func() {
if r := recover(); r != nil {
err, ok := r.(error)
@@ -80,8 +80,8 @@ func (s *Syncer) syncSlowQuery(ctx context.Context, instance *api.Instance) {
}()
find := &store.FindInstanceMessage{}
- if instance != nil {
- find.UID = &instance.ID
+ if instanceResourceID != nil {
+ find.ResourceID = instanceResourceID
}
instances, err := s.store.ListInstancesV2(ctx, find)
if err != nil {
diff --git a/backend/server/server.go b/backend/server/server.go
index 293b570509..5ab606462c 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -328,7 +328,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.stateCfg = &state.State{
InstanceDatabaseSyncChan: make(chan *store.InstanceMessage, 100),
- InstanceSlowQuerySyncChan: make(chan *api.Instance, 100),
+ InstanceSlowQuerySyncChan: make(chan string, 100),
InstanceOutstandingConnections: make(map[int]int),
IssueExternalApprovalRelayCancelChan: make(chan int, 1),
}
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 10a3459745..2cd0aa2cfc 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -15,25 +15,6 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-// GetPrincipalList gets a list of Principal instances.
-func (s *Store) GetPrincipalList(ctx context.Context) ([]*api.Principal, error) {
- users, err := s.ListUsers(ctx, &FindUserMessage{ShowDeleted: true})
- if err != nil {
- return nil, errors.Wrap(err, "failed to find Principal list")
- }
- var principalList []*api.Principal
- for _, user := range users {
- principal, err := composePrincipal(user)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to compose Principal role with user[%+v]", user)
- }
- if principal != nil {
- principalList = append(principalList, principal)
- }
- }
- return principalList, nil
-}
-
// GetPrincipalByID gets an instance of Principal by ID.
func (s *Store) GetPrincipalByID(ctx context.Context, id int) (*api.Principal, error) {
user, err := s.GetUserByID(ctx, id)