Skip to content

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

refactor: cleanup legacy code (#8456)

Danny Xu5d0b9da50214
diff --git a/backend/component/activity/manager.go b/backend/component/activity/manager.go
index 117f8c35b5..9899f43aae 100644
--- a/backend/component/activity/manager.go
+++ b/backend/component/activity/manager.go
@@ -568,13 +568,9 @@ func (m *Manager) getWebhookContext(ctx context.Context, activity *store.Activit
return nil, err
}
link += fmt.Sprintf("?stage=%d", payload.StageID)
- switch payload.StageStatusUpdateType {
- case api.StageStatusUpdateTypeBegin:
- title = fmt.Sprintf("Stage begins - %s", payload.StageName)
- case api.StageStatusUpdateTypeEnd:
+ if payload.StageStatusUpdateType == api.StageStatusUpdateTypeEnd {
title = fmt.Sprintf("Stage ends - %s", payload.StageName)
}
-
case api.ActivityPipelineTaskStatusUpdate:
update := &api.ActivityPipelineTaskStatusUpdatePayload{}
if err := json.Unmarshal([]byte(activity.Payload), update); err != nil {
diff --git a/backend/legacyapi/api_dependency_gate.go b/backend/legacyapi/api_dependency_gate.go
deleted file mode 100644
index 5c517c989c..0000000000
--- a/backend/legacyapi/api_dependency_gate.go
+++ /dev/null
@@ -1,17 +0,0 @@
-//go:build !release
-
-package api
-
-// The idea of dependency gate is to use compiler check to prevent introducing unintended dependency.
-// In particular:
-// 1. the plugin package should NOT depend on the api package as the plugin package should be self-contained.
-
-import (
- // dependency gate.
- _ "github.com/bytebase/bytebase/backend/plugin/advisor"
- _ "github.com/bytebase/bytebase/backend/plugin/db"
- _ "github.com/bytebase/bytebase/backend/plugin/metric"
- _ "github.com/bytebase/bytebase/backend/plugin/parser/sql"
- _ "github.com/bytebase/bytebase/backend/plugin/vcs"
- _ "github.com/bytebase/bytebase/backend/plugin/webhook"
-)
diff --git a/backend/legacyapi/data_source.go b/backend/legacyapi/data_source.go
index 25a31a04e4..e620a5baf8 100644
--- a/backend/legacyapi/data_source.go
+++ b/backend/legacyapi/data_source.go
@@ -1,10 +1,5 @@
package api
-import (
- "encoding/json"
- "errors"
-)
-
// DataSourceType is the type of data source.
type DataSourceType string
@@ -14,56 +9,3 @@ const (
// RO is the read-only type of data source.
RO DataSourceType = "RO"
)
-
-// DataSourceOptions is the options for a data source.
-type DataSourceOptions struct {
- // SRV is used for MongoDB only.
- SRV bool `json:"srv" jsonapi:"attr,srv"`
- // AuthenticationDatabase is used for MongoDB only.
- AuthenticationDatabase string `json:"authenticationDatabase" jsonapi:"attr,authenticationDatabase"`
- // SID and ServiceName are used for Oracle.
- SID string `json:"sid" jsonapi:"attr,sid"`
- ServiceName string `json:"serviceName" jsonapi:"attr,serviceName"`
- SSHHost string `json:"sshHost" jsonapi:"attr,sshHost"`
- SSHPort string `json:"sshPort" jsonapi:"attr,sshPort"`
- SSHUser string `json:"sshUser" jsonapi:"attr,sshUser"`
- SSHPassword string `json:"sshPassword" jsonapi:"attr,sshPassword"`
- SSHPrivateKey string `json:"sshPrivateKey" jsonapi:"attr,sshPrivateKey"`
-}
-
-// getDefaultDataSourceOptions returns the default data source options.
-func getDefaultDataSourceOptions() DataSourceOptions {
- return DataSourceOptions{}
-}
-
-// Scan implements database/sql Scanner interface, converts JSONB to DataSourceOptions struct.
-func (d *DataSourceOptions) Scan(src any) error {
- if bs, ok := src.([]byte); ok {
- if string(bs) == "{}" {
- // handle '{}', return default values
- *d = getDefaultDataSourceOptions()
- return nil
- }
- return json.Unmarshal(bs, d)
- }
- return errors.New("failed to scan data source options")
-}
-
-// DataSource is the API message for a data source.
-type DataSource struct {
- ID int `jsonapi:"primary,dataSource"`
-
- // Related fields
- // Just returns InstanceID and DatabaseID otherwise would cause circular dependency.
- InstanceID int `jsonapi:"attr,instanceId"`
- DatabaseID int `jsonapi:"attr,databaseId"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Type DataSourceType `jsonapi:"attr,type"`
- Username string `jsonapi:"attr,username"`
- Host string `jsonapi:"attr,host"`
- Port string `jsonapi:"attr,port"`
- Options DataSourceOptions `jsonapi:"attr,options"`
- Database string `jsonapi:"attr,database"`
-}
diff --git a/backend/legacyapi/database.go b/backend/legacyapi/database.go
index 598a1e4ab1..6f1efb2261 100644
--- a/backend/legacyapi/database.go
+++ b/backend/legacyapi/database.go
@@ -14,48 +14,6 @@ const (
NotFound SyncStatus = "NOT_FOUND"
)
-// Database is the API message for a database.
-type Database struct {
- ID int `jsonapi:"primary,database"`
-
- // Related fields
- ProjectID int `jsonapi:"attr,projectId"`
- Project *Project `jsonapi:"relation,project"`
- InstanceID int `jsonapi:"attr,instanceId"`
- Instance *Instance `jsonapi:"relation,instance"`
- DataSourceList []*DataSource `jsonapi:"relation,dataSource"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- SchemaVersion string `jsonapi:"attr,schemaVersion"`
- SyncStatus SyncStatus `jsonapi:"attr,syncStatus"`
- LastSuccessfulSyncTs int64 `jsonapi:"attr,lastSuccessfulSyncTs"`
- // Labels is a json-encoded string from a list of DatabaseLabel,
- // e.g. "[{"key":"bb.location","value":"earth"},{"key":"bb.tenant","value":"bytebase"}]".
- Labels string `jsonapi:"attr,labels,omitempty"`
-}
-
-// DatabaseFind is the API message for finding databases.
-type DatabaseFind struct {
- ID *int
-
- // Related fields
- ProjectID *int
- InstanceID *int
-
- // Domain specific fields
- Name *string
- SyncStatus *SyncStatus
-}
-
-func (find *DatabaseFind) String() string {
- str, err := json.Marshal(*find)
- if err != nil {
- return err.Error()
- }
- return string(str)
-}
-
// DatabaseEdit is the API message for updating a database in UI editor.
type DatabaseEdit struct {
DatabaseID int `json:"databaseId"`
diff --git a/backend/legacyapi/environment.go b/backend/legacyapi/environment.go
index b16151a90b..a0a16e6167 100644
--- a/backend/legacyapi/environment.go
+++ b/backend/legacyapi/environment.go
@@ -6,26 +6,6 @@ import (
"github.com/pkg/errors"
)
-// Environment is the API message for an environment.
-type Environment struct {
- ID int `jsonapi:"primary,environment"`
- ResourceID string `jsonapi:"attr,resourceId"`
-
- // Standard fields
- RowStatus RowStatus `jsonapi:"attr,rowStatus"`
- CreatorID int
- Creator *Principal
- CreatedTs int64
- UpdaterID int
- Updater *Principal
- UpdatedTs int64
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Order int `jsonapi:"attr,order"`
- Tier EnvironmentTierValue `jsonapi:"attr,tier"`
-}
-
// placeholderRegexp is the regexp for placeholder.
// Refer to https://stackoverflow.com/a/6222235/19075342, but we support '.' for now.
var placeholderRegexp = regexp.MustCompile(`[^\\/?%*:|"<>]+`)
diff --git a/backend/legacyapi/instance.go b/backend/legacyapi/instance.go
deleted file mode 100644
index f86ab9937e..0000000000
--- a/backend/legacyapi/instance.go
+++ /dev/null
@@ -1,30 +0,0 @@
-package api
-
-import (
- "github.com/bytebase/bytebase/backend/plugin/db"
-)
-
-// Instance is the API message for an instance.
-type Instance struct {
- ID int `jsonapi:"primary,instance"`
- ResourceID string `jsonapi:"attr,resourceId"`
- RowStatus RowStatus `jsonapi:"attr,rowStatus"`
-
- // Related fields
- EnvironmentID int
- Environment *Environment `jsonapi:"relation,environment"`
- DataSourceList []*DataSource `jsonapi:"relation,dataSourceList"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Engine db.Type `jsonapi:"attr,engine"`
- EngineVersion string `jsonapi:"attr,engineVersion"`
- ExternalLink string `jsonapi:"attr,externalLink"`
- Host string `jsonapi:"attr,host"`
- Port string `jsonapi:"attr,port"`
- // Database is the initial connection database for PostgreSQL only.
- Database string `jsonapi:"attr,database"`
- Username string `jsonapi:"attr,username"`
- // Password is not returned to the client
- Password string
-}
diff --git a/backend/legacyapi/principal.go b/backend/legacyapi/principal.go
index 95b5e84475..d9c24ab11a 100644
--- a/backend/legacyapi/principal.go
+++ b/backend/legacyapi/principal.go
@@ -1,9 +1,5 @@
package api
-import (
- "encoding/json"
-)
-
// SystemBotID is the ID of the system robot.
const SystemBotID = 1
@@ -42,41 +38,3 @@ const (
// PrincipalAuthProviderGitHub is the GitHub (for both GitHub.com and GitHub Enterprise) authentication provider.
PrincipalAuthProviderGitHub PrincipalAuthProvider = "GITHUB"
)
-
-// Principal is the API message for principals.
-type Principal struct {
- ID int `jsonapi:"primary,principal"`
-
- // Domain specific fields
- Type PrincipalType `jsonapi:"attr,type"`
- Name string `jsonapi:"attr,name"`
- Email string `jsonapi:"attr,email"`
- // Do not return to the client
- PasswordHash string
- // Role is stored in the member table, but we include it when returning the principal.
- // This simplifies the client code where it won't require order dependency to fetch the related member info first.
- Role Role `jsonapi:"attr,role"`
- // The ServiceKey is the password, only used for SERVICE_ACCOUNT.
- // We only return the service key for the first time after the creation for SERVICE_ACCOUNT.
- ServiceKey string `jsonapi:"attr,serviceKey"`
-}
-
-// MarshalJSON customizes the Principal Marshal method so the returned object
-// can map directly to the frontend Principal object without any conversion.
-func (p *Principal) MarshalJSON() ([]byte, error) {
- return json.Marshal(&struct {
- ID int `json:"id"`
- Type PrincipalType `json:"type"`
- Name string `json:"name"`
- Email string `json:"email"`
- Role Role `json:"role"`
- ServiceKey string `json:"serviceKey"`
- }{
- ID: p.ID,
- Type: p.Type,
- Name: p.Name,
- Email: p.Email,
- Role: p.Role,
- ServiceKey: p.ServiceKey,
- })
-}
diff --git a/backend/legacyapi/project.go b/backend/legacyapi/project.go
index 8696014c6e..3c93ff486e 100644
--- a/backend/legacyapi/project.go
+++ b/backend/legacyapi/project.go
@@ -74,29 +74,6 @@ const (
ProjectSchemaChangeTypeSDL ProjectSchemaChangeType = "SDL"
)
-// Project is the API message for a project.
-type Project struct {
- ID int `jsonapi:"primary,project"`
- ResourceID string `jsonapi:"attr,resourceId"`
- RowStatus RowStatus `jsonapi:"attr,rowStatus"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Key string `jsonapi:"attr,key"`
- WorkflowType ProjectWorkflowType `jsonapi:"attr,workflowType"`
- Visibility ProjectVisibility `jsonapi:"attr,visibility"`
- TenantMode ProjectTenantMode `jsonapi:"attr,tenantMode"`
- // DBNameTemplate is only used when a project is in tenant mode and the name of tenant databases follows a format.
- // {{DB_NAME}} is used for each tenant belonging to an individual database instance and all tenant databases have the same database name.
- // The template can include label keys such as {{DB_NAME}}_{{TENANT}}. It allows all tenant databases to belong to one or a few database instances.
- // All database with the same {{DB_NAME}} (base database name) belong to one group.
- //
- // Empty value means all tenant databases in the project belonging to the same group.
- DBNameTemplate string `jsonapi:"attr,dbNameTemplate"`
- // SchemaChangeType is the type of the schema migration script.
- SchemaChangeType ProjectSchemaChangeType `jsonapi:"attr,schemaChangeType"`
-}
-
var (
// DBNameToken is the token for database name.
DBNameToken = "{{DB_NAME}}"
diff --git a/backend/legacyapi/project_webhook.go b/backend/legacyapi/project_webhook.go
deleted file mode 100644
index 52d95cb52f..0000000000
--- a/backend/legacyapi/project_webhook.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package api
-
-// ProjectWebhook is the API message for project webhooks.
-type ProjectWebhook struct {
- ID int `jsonapi:"primary,projectWebhookMember"`
-
- // Related fields
- // Just returns ProjectID since it always operates within the project context
- ProjectID int `jsonapi:"attr,projectId"`
-
- // Domain specific fields
- Type string `jsonapi:"attr,type"`
- Name string `jsonapi:"attr,name"`
- URL string `jsonapi:"attr,url"`
- ActivityList []string `jsonapi:"attr,activityList"`
-}
-
-// ProjectWebhookCreate is the API message for creating a project webhook.
-type ProjectWebhookCreate struct {
- // Standard fields
- // Value is assigned from the jwt subject field passed by the client.
- CreatorID int
-
- // Related fields
- ProjectID int
-
- // Domain specific fields
- Type string `jsonapi:"attr,type"`
- Name string `jsonapi:"attr,name"`
- URL string `jsonapi:"attr,url"`
- ActivityList []string `jsonapi:"attr,activityList"`
-}
-
-// ProjectWebhookPatch is the API message for patching a project webhook.
-type ProjectWebhookPatch struct {
- ID int
-
- // Standard fields
- // Value is assigned from the jwt subject field passed by the client.
- UpdaterID int
-
- // Domain specific fields
- Name *string `jsonapi:"attr,name"`
- URL *string `jsonapi:"attr,url"`
- ActivityList *string `jsonapi:"attr,activityList"`
-}
-
-// ProjectWebhookTestResult is the test result of a project webhook.
-type ProjectWebhookTestResult struct {
- Error string `jsonapi:"attr,error"`
-}
diff --git a/backend/legacyapi/sheet.go b/backend/legacyapi/sheet.go
index 2c31ad6a21..050b1f98a9 100644
--- a/backend/legacyapi/sheet.go
+++ b/backend/legacyapi/sheet.go
@@ -27,22 +27,3 @@ const (
// SheetFromBitbucket is the sheet synced from Bitbucket.
SheetFromBitbucket SheetSource = "BITBUCKET"
)
-
-// SheetType is the type of sheet.
-type SheetType string
-
-const (
- // SheetForSQL is the sheet that used for saving SQL statements.
- SheetForSQL SheetType = "SQL"
-)
-
-// SheetVCSPayload is the additional data payload of the VCS sheet.
-// The sheet source should be one of SheetFromGitLab and SheetFromGitHub.
-type SheetVCSPayload struct {
- FileName string `json:"fileName"`
- FilePath string `json:"filePath"`
- Size int64 `json:"size"`
- Author string `json:"author"`
- LastCommitID string `json:"lastCommitId"`
- LastSyncTs int64 `json:"lastSyncTs"`
-}
diff --git a/backend/legacyapi/stage.go b/backend/legacyapi/stage.go
index 50bdacdcda..b6837607c3 100644
--- a/backend/legacyapi/stage.go
+++ b/backend/legacyapi/stage.go
@@ -5,8 +5,6 @@ package api
type StageStatusUpdateType string
const (
- // StageStatusUpdateTypeBegin means the stage begins. A stage only begins once.
- StageStatusUpdateTypeBegin StageStatusUpdateType = "BEGIN"
// StageStatusUpdateTypeEnd means the stage ends. A stage can end multiple times.
// A stage ends if its contained tasks have finished running, i.e. the status of which is one of
// - DONE
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index 12ffb30907..b5f7da18fa 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -231,42 +231,6 @@ type TaskDatabaseBackupPayload struct {
BackupID int `json:"backupId,omitempty"`
}
-// Task is the API message for a task.
-type Task struct {
- ID int `jsonapi:"primary,task"`
-
- // Standard fields
- CreatorID int
- Creator *Principal `jsonapi:"relation,creator"`
- CreatedTs int64 `jsonapi:"attr,createdTs"`
- UpdaterID int
- Updater *Principal `jsonapi:"relation,updater"`
- UpdatedTs int64 `jsonapi:"attr,updatedTs"`
-
- // Related fields
- // Just returns PipelineID and StageID otherwise would cause circular dependency.
- PipelineID int `jsonapi:"attr,pipelineId"`
- StageID int `jsonapi:"attr,stageId"`
- InstanceID int
- Instance *Instance `jsonapi:"relation,instance"`
- // Could be empty for creating database task when the task isn't yet completed successfully.
- DatabaseID *int
- Database *Database `jsonapi:"relation,database"`
- TaskRunList []*TaskRun `jsonapi:"relation,taskRun"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Status TaskStatus `jsonapi:"attr,status"`
- Type TaskType `jsonapi:"attr,type"`
- Payload string `jsonapi:"attr,payload"`
- EarliestAllowedTs int64 `jsonapi:"attr,earliestAllowedTs"`
- // BlockedBy is an array of Task ID.
- // We use string here to workaround jsonapi limitations. https://github.com/google/jsonapi/issues/209
- BlockedBy []string `jsonapi:"attr,blockedBy"`
- // For v1 api compatibility.
- LatestTaskRunStatus TaskRunStatus
-}
-
// Progress is a generalized struct which can track the progress of a task.
type Progress struct {
// TotalUnit is the total unit count of the task
diff --git a/backend/legacyapi/task_run.go b/backend/legacyapi/task_run.go
index 7659972403..243dfa8003 100644
--- a/backend/legacyapi/task_run.go
+++ b/backend/legacyapi/task_run.go
@@ -1,9 +1,5 @@
package api
-import (
- "github.com/bytebase/bytebase/backend/common"
-)
-
// TaskRunStatus is the status of a task run.
type TaskRunStatus string
@@ -33,28 +29,3 @@ type TaskRunResultPayload struct {
ChangeHistory string `json:"changeHistory,omitempty"`
Version string `json:"version,omitempty"`
}
-
-// TaskRun is the API message for a task run.
-type TaskRun struct {
- ID int `jsonapi:"primary,taskRun"`
-
- // Standard fields
- CreatorID int
- Creator *Principal `jsonapi:"relation,creator"`
- CreatedTs int64 `jsonapi:"attr,createdTs"`
- UpdaterID int
- Updater *Principal `jsonapi:"relation,updater"`
- UpdatedTs int64 `jsonapi:"attr,updatedTs"`
-
- // Related fields
- TaskID int `jsonapi:"attr,taskId"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Status TaskRunStatus `jsonapi:"attr,status"`
- Type TaskType `jsonapi:"attr,type"`
- Code common.Code `jsonapi:"attr,code"`
- Comment string `jsonapi:"attr,comment"`
- Result string `jsonapi:"attr,result"`
- Payload string `jsonapi:"attr,payload"`
-}
diff --git a/backend/metric/collector/sheet_count.go b/backend/metric/collector/sheet_count.go
index 9f9fa62417..b1c197a722 100644
--- a/backend/metric/collector/sheet_count.go
+++ b/backend/metric/collector/sheet_count.go
@@ -39,7 +39,6 @@ func (c *sheetCountCollector) Collect(ctx context.Context) ([]*metric.Metric, er
"row_status": string(sheetCountMetric.RowStatus),
"visibility": string(sheetCountMetric.Visibility),
"source": string(sheetCountMetric.Source),
- "type": string(sheetCountMetric.Type),
},
})
}
diff --git a/backend/metric/metric.go b/backend/metric/metric.go
index 4957997449..b4746c853e 100644
--- a/backend/metric/metric.go
+++ b/backend/metric/metric.go
@@ -99,7 +99,6 @@ type SheetCountMetric struct {
RowStatus api.RowStatus
Visibility api.SheetVisibility
Source api.SheetSource
- Type api.SheetType
Count int
}
diff --git a/backend/store/stats.go b/backend/store/stats.go
index ef9e77d8ef..1c62a9b237 100644
--- a/backend/store/stats.go
+++ b/backend/store/stats.go
@@ -358,7 +358,6 @@ func (s *Store) CountSheetGroupByRowstatusVisibilitySourceAndType(ctx context.Co
&sheetCount.RowStatus,
&sheetCount.Visibility,
&sheetCount.Source,
- &sheetCount.Type,
&sheetCount.Count,
); err != nil {
return nil, err