Skip to content

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

chore: remove unused code (#8011)

Danny Xue2e65bef9c0e
diff --git a/backend/api/v1/docs.go b/backend/api/v1/docs.go
deleted file mode 100644
index a7960ee7a5..0000000000
--- a/backend/api/v1/docs.go
+++ /dev/null
@@ -1,2 +0,0 @@
-// Package v1 is the implementation of v1 API service.
-package v1
diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.go
index 4175a091bf..e5d5b099a3 100644
--- a/backend/bin/server/cmd/root.go
+++ b/backend/bin/server/cmd/root.go
@@ -256,11 +256,7 @@ func start() {
return
}
- schemaVersion := ""
- if s.SchemaVersion != nil {
- schemaVersion = fmt.Sprintf("(schema version %v) ", s.SchemaVersion)
- }
- fmt.Printf(greetingBanner, fmt.Sprintf("Version %s %shas started on port %d 🚀", profile.Version, schemaVersion, flags.port))
+ fmt.Printf(greetingBanner, fmt.Sprintf("Version %s has started on port %d 🚀", profile.Version, flags.port))
// Execute program.
if err := s.Run(ctx, flags.port); err != nil {
diff --git a/backend/legacyapi/external_approval.go b/backend/legacyapi/external_approval.go
index 11cbf0c6c8..2faf452832 100644
--- a/backend/legacyapi/external_approval.go
+++ b/backend/legacyapi/external_approval.go
@@ -10,18 +10,6 @@ const (
ExternalApprovalTypeRelay ExternalApprovalType = "bb.plugin.app.relay"
)
-// ExternalApprovalPayloadFeishu is the payload for feishu type ExternalApproval.
-type ExternalApprovalPayloadFeishu struct {
- StageID int
- AssigneeID int
-
- // Feishu
- InstanceCode string
- RequesterID string
- // Rejected tells if the approval has been rejected on Feishu.
- Rejected bool
-}
-
// ExternalApprovalPayloadRelay is the payload for relay type ExternalApproval.
type ExternalApprovalPayloadRelay struct {
ExternalApprovalNodeID string `json:"externalApprovalNodeId"`
@@ -44,16 +32,3 @@ type ExternalApprovalEvent struct {
Action ExternalApprovalEventActionType `json:"action"`
StageName string `json:"stageName"`
}
-
-const (
- // ExternalApprovalCancelReasonGeneral is the general reason, used as a default.
- ExternalApprovalCancelReasonGeneral string = "Canceled because the assignee has been changed, or the SQL has been modified, or all tasks of the stage have been approved or the issue is no longer open."
- // ExternalApprovalCancelReasonIssueNotOpen is used if the issue is not open.
- ExternalApprovalCancelReasonIssueNotOpen string = "Canceled because the containing issue is no longer open."
- // ExternalApprovalCancelReasonReassigned is used if the assignee has been changed.
- ExternalApprovalCancelReasonReassigned string = "Canceled because the assignee has changed."
- // ExternalApprovalCancelReasonSQLModified is used if the task SQL statement has been modified.
- ExternalApprovalCancelReasonSQLModified string = "Canceled because the SQL has been modified."
- // ExternalApprovalCancelReasonNoTaskPendingApproval is used if there is no pending approval tasks.
- ExternalApprovalCancelReasonNoTaskPendingApproval string = "Canceled because all tasks have been approved."
-)
diff --git a/backend/legacyapi/instance_user.go b/backend/legacyapi/instance_user.go
deleted file mode 100644
index 6cbf34bed5..0000000000
--- a/backend/legacyapi/instance_user.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package api
-
-import (
- "encoding/json"
-)
-
-// InstanceUser is the API message for instance user.
-type InstanceUser struct {
- ID string `jsonapi:"primary,instanceUser"`
-
- // Related fields
- InstanceID int `jsonapi:"attr,instanceId"`
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Grant string `jsonapi:"attr,grant"`
-}
-
-// InstanceUserUpsert is the API message for upserting an instance user.
-type InstanceUserUpsert struct {
- // Standard fields
- CreatorID int
-
- // Related fields
- InstanceID int
-
- // Domain specific fields
- Name string `jsonapi:"attr,name"`
- Grant string `jsonapi:"attr,grant"`
-}
-
-// InstanceUserFind is the API message for finding instance users.
-type InstanceUserFind struct {
- ID *string
-
- // Related fields
- InstanceID *int
-}
-
-func (find *InstanceUserFind) String() string {
- str, err := json.Marshal(*find)
- if err != nil {
- return err.Error()
- }
- return string(str)
-}
-
-// InstanceUserDelete is the API message for deleting an instance user.
-type InstanceUserDelete struct {
- ID string
-}
diff --git a/backend/legacyapi/slug.go b/backend/legacyapi/slug.go
deleted file mode 100644
index f0f4a581b7..0000000000
--- a/backend/legacyapi/slug.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package api
-
-import (
- "fmt"
-
- "github.com/gosimple/slug"
-)
-
-// IssueSlug is the slug formatter for issuees.
-func IssueSlug(issue *Issue) string {
- return fmt.Sprintf("%s-%d", slug.Make(issue.Name), issue.ID)
-}
-
-// ProjectShortSlug is the slug short formatter for Project.
-func ProjectShortSlug(project *Project) string {
- return slug.Make(project.Name)
-}
-
-// EnvSlug is the slug formatter for environments.
-func EnvSlug(env *Environment) string {
- return slug.Make(env.Name)
-}
-
-// ProjectWebhookSlug is the slug formatter for project webhooks.
-func ProjectWebhookSlug(name string, id int) string {
- return fmt.Sprintf("%s-%d", slug.Make(name), id)
-}
diff --git a/backend/legacyapi/sql.go b/backend/legacyapi/sql.go
deleted file mode 100644
index 579a7e06af..0000000000
--- a/backend/legacyapi/sql.go
+++ /dev/null
@@ -1,46 +0,0 @@
-package api
-
-import (
- "github.com/bytebase/bytebase/backend/plugin/advisor"
-)
-
-// SQLSyncSchema is the API message for sync schemas.
-type SQLSyncSchema struct {
- InstanceID *int `jsonapi:"attr,instanceId"`
- DatabaseID *int `jsonapi:"attr,databaseId"`
-}
-
-// SQLExecute is the API message for execute SQL.
-// We only support readonly / SELECT.
-type SQLExecute struct {
- InstanceID int `jsonapi:"attr,instanceId"`
- // For engines such as MySQL, databaseName can be empty.
- DatabaseName string `jsonapi:"attr,databaseName"`
- Statement string `jsonapi:"attr,statement"`
- // For now, Readonly must be true
- Readonly bool `jsonapi:"attr,readonly"`
- // The maximum row count returned, only applicable to SELECT query.
- // Not enforced if limit <= 0.
- Limit int `jsonapi:"attr,limit"`
- // ExportFomat includes QUERY, CSV, JSON.
- // QUERY is used for querying database. CSV and JSON are the formats used for exporting data.
- ExportFormat string `jsonapi:"attr,exportFormat"`
-}
-
-// SingleSQLResult is the API message for single SQL result.
-type SingleSQLResult struct {
- // A list of rows marshalled into a JSON.
- Data string `jsonapi:"attr,data" json:"data"`
- // SQL operation may fail for connection issue and there is no proper http status code for it, so we return error in the response body.
- Error string `jsonapi:"attr,error" json:"error"`
-}
-
-// SQLResultSet is the API message for SQL results.
-type SQLResultSet struct {
- // A list of SQL results.
- SingleSQLResultList []SingleSQLResult `jsonapi:"attr,singleSQLResultList"`
- // Error of the whole SQL execution.
- Error string `jsonapi:"attr,error"`
- // A list of SQL check advice.
- AdviceList []advisor.Advice `jsonapi:"attr,adviceList"`
-}
diff --git a/backend/legacyapi/stage.go b/backend/legacyapi/stage.go
index b68e6dd4a3..5224c8dd4b 100644
--- a/backend/legacyapi/stage.go
+++ b/backend/legacyapi/stage.go
@@ -29,16 +29,3 @@ type Stage struct {
// Domain specific fields
Name string `jsonapi:"attr,name"`
}
-
-// StageAllTaskStatusPatch is the API message for patching task status for all tasks in a stage.
-type StageAllTaskStatusPatch struct {
- ID int
-
- // Standard fields
- // Value is assigned from the jwt subject field passed by the client.
- UpdaterID int
-
- // Domain specific fields
- Status TaskStatus `jsonapi:"attr,status"`
- Comment *string `jsonapi:"attr,comment"`
-}
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index 37b0003203..d0073c25a5 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -252,10 +252,9 @@ type Task struct {
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"`
- TaskCheckRunList []*TaskCheckRun `jsonapi:"relation,taskCheckRun"`
+ DatabaseID *int
+ Database *Database `jsonapi:"relation,database"`
+ TaskRunList []*TaskRun `jsonapi:"relation,taskRun"`
// Domain specific fields
Name string `jsonapi:"attr,name"`
@@ -266,10 +265,6 @@ type Task struct {
// 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"`
- // Progress is loaded from the task scheduler in memory, NOT from the database
- Progress Progress `jsonapi:"attr,progress"`
- // OUTPUT ONLY, used by grouping batch change.
- Statement string `jsonapi:"attr,statement"`
// For v1 api compatibility.
LatestTaskRunStatus TaskRunStatus
}
diff --git a/backend/legacyapi/task_check_run.go b/backend/legacyapi/task_check_run.go
index c41dfec349..6d1d50d8dd 100644
--- a/backend/legacyapi/task_check_run.go
+++ b/backend/legacyapi/task_check_run.go
@@ -2,8 +2,6 @@ package api
import (
"github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/plugin/advisor"
- advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db"
"github.com/bytebase/bytebase/backend/plugin/db"
)
@@ -130,30 +128,6 @@ type TaskCheckRun struct {
Payload string `jsonapi:"attr,payload"`
}
-// IsSQLReviewSupported checks the engine type if SQL review supports it.
-func IsSQLReviewSupported(dbType db.Type) bool {
- if dbType == db.Postgres || dbType == db.MySQL || dbType == db.TiDB || dbType == db.MariaDB || dbType == db.Oracle || dbType == db.OceanBase || dbType == db.Snowflake || dbType == db.MSSQL {
- advisorDB, err := advisorDB.ConvertToAdvisorDBType(string(dbType))
- if err != nil {
- return false
- }
-
- return advisor.IsSQLReviewSupported(advisorDB)
- }
-
- return false
-}
-
-// IsStatementTypeCheckSupported checks the engine type if statement type check supports it.
-func IsStatementTypeCheckSupported(dbType db.Type) bool {
- switch dbType {
- case db.Postgres, db.TiDB, db.MySQL, db.MariaDB, db.OceanBase:
- return true
- default:
- return false
- }
-}
-
// IsTaskCheckReportSupported checks if the task report supports the engine type.
func IsTaskCheckReportSupported(dbType db.Type) bool {
switch dbType {
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index cf8148bc93..b590ce423e 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -771,6 +771,7 @@ func getTaskRiskLevel(ctx context.Context, s *store.Store, issue *store.IssueMes
}
var affectedRowsReportResult, statementTypeReportResult []api.TaskCheckResult
+ // TODO(d): migrate to v2 CI/CD.
if api.IsTaskCheckReportSupported(instance.Engine) && api.IsTaskCheckReportNeededForTaskType(task.Type) {
affectedRowsReportResultInner, done, err := getReportResult(ctx, s, task, api.TaskCheckDatabaseStatementAffectedRowsReport)
if err != nil {
diff --git a/backend/server/openapi_sql.go b/backend/server/openapi_sql.go
index 1a72ba5a10..8294974b76 100644
--- a/backend/server/openapi_sql.go
+++ b/backend/server/openapi_sql.go
@@ -1,8 +1,6 @@
package server
import (
- "context"
- "database/sql"
"encoding/json"
"fmt"
"io"
@@ -10,183 +8,12 @@ import (
"github.com/labstack/echo/v4"
- "github.com/bytebase/bytebase/backend/common"
- metricAPI "github.com/bytebase/bytebase/backend/metric"
- "github.com/bytebase/bytebase/backend/plugin/advisor"
- "github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
- advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db"
"github.com/bytebase/bytebase/backend/plugin/db"
- "github.com/bytebase/bytebase/backend/plugin/metric"
parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"
"github.com/bytebase/bytebase/backend/plugin/parser/sql/differ"
- "github.com/bytebase/bytebase/backend/store"
)
-var (
- _ catalog.Catalog = (*catalogService)(nil)
-)
-
-// catalogService is the catalog service for sql check api.
-type catalogService struct {
- finder *catalog.Finder
-}
-
-func newCatalogService(dbType advisorDB.Type) *catalogService {
- return &catalogService{
- finder: catalog.NewEmptyFinder(&catalog.FinderContext{CheckIntegrity: false, EngineType: dbType}),
- }
-}
-
-// GetFinder is the API message in catalog.
-func (c *catalogService) GetFinder() *catalog.Finder {
- return c.finder
-}
-
-type sqlCheckRequestBody struct {
- Statement string `json:"statement"`
- DatabaseType string `json:"databaseType"`
- DatabaseName string `json:"databaseName"`
- EnvironmentName string `json:"environmentName"`
- Host string `json:"host"`
- Port string `json:"port"`
-}
-
-// sqlCheckController godoc
-// @Summary Check the SQL statement.
-// @Description Parse and check the SQL statement according to the SQL review policy.
-// @Accept */*
-// @Tags SQL review
-// @Produce json
-// @Param environmentName body string true "The environment name. Case sensitive."
-// @Param statement body string true "The SQL statement."
-// @Param databaseType body string false "The database type. Required if the port, host and database name is not specified." Enums(MYSQL, POSTGRES, TIDB, OCEANBASE)
-// @Param host body string false "The instance host."
-// @Param port body string false "The instance port."
-// @Param databaseName body string false "The database name in the instance."
-// @Success 200 {array} advisor.Advice
-// @Failure 400 {object} echo.HTTPError
-// @Failure 500 {object} echo.HTTPError
-// @Router /sql/advise [post].
-func (s *Server) sqlCheckController(c echo.Context) error {
- request := &sqlCheckRequestBody{}
- body, err := io.ReadAll(c.Request().Body)
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, "Failed to read request body").SetInternal(err)
- }
- if err := json.Unmarshal(body, request); err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, "Cannot format request body").SetInternal(err)
- }
-
- // EnvironmentName is the environment resource ID.
- if request.EnvironmentName == "" {
- return echo.NewHTTPError(http.StatusBadRequest, "Missing required environment name")
- }
-
- if request.Statement == "" {
- return echo.NewHTTPError(http.StatusBadRequest, "Missing required SQL statement")
- }
-
- ctx := c.Request().Context()
- var databaseType string
- var catalog catalog.Catalog
- var driver db.Driver
- var connection *sql.DB
-
- if request.DatabaseName != "" && request.Host != "" && request.Port != "" {
- instances, err := s.store.ListInstancesV2(ctx, &store.FindInstanceMessage{})
- if err != nil {
- return err
- }
- var instance *store.InstanceMessage
- for _, v := range instances {
- for _, d := range v.DataSources {
- if d.Host == request.Host && d.Port == request.Port {
- instance = v
- break
- }
- }
- if instance != nil {
- break
- }
- }
- if instance == nil {
- return echo.NewHTTPError(http.StatusNotFound, "instance not found with host and port")
- }
- database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{
- InstanceID: &instance.ResourceID,
- DatabaseName: &request.DatabaseName,
- IgnoreCaseSensitive: store.IgnoreDatabaseAndTableCaseSensitive(instance),
- })
- if err != nil {
- return err
- }
- if database == nil {
- return echo.NewHTTPError(http.StatusNotFound, "database not found")
- }
-
- dbType := instance.Engine
- databaseType = string(dbType)
- // TODO(rebelice): support SDL mode for open api.
- catalog, err = s.store.NewCatalog(ctx, database.UID, dbType, advisor.SyntaxModeNormal)
- if err != nil {
- return err
- }
- driver, err = s.dbFactory.GetReadOnlyDatabaseDriver(ctx, instance, database)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get database driver").SetInternal(err)
- }
- defer driver.Close(ctx)
- connection = driver.GetDB()
- } else {
- databaseType = request.DatabaseType
- if databaseType == "" {
- return echo.NewHTTPError(http.StatusBadRequest, "Missing required database type")
- }
- }
-
- advisorDBType, err := advisorDB.ConvertToAdvisorDBType(databaseType)
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Database %s is not support", databaseType))
- }
- if catalog == nil {
- catalog = newCatalogService(advisorDBType)
- }
-
- environment, err := s.store.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{ResourceID: &request.EnvironmentName})
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Failed to find environment %s", request.EnvironmentName)).SetInternal(err)
- }
- if environment == nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid environment %s", request.EnvironmentName))
- }
-
- _, adviceList, err := s.sqlCheck(
- ctx,
- advisorDBType,
- "utf8mb4",
- "utf8mb4_general_ci",
- environment.UID,
- request.Statement,
- catalog,
- connection,
- )
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to run sql check").SetInternal(err)
- }
-
- s.metricReporter.Report(ctx, &metric.Metric{
- Name: metricAPI.SQLAdviseAPIMetricName,
- Value: 1,
- Labels: map[string]any{
- "database_type": databaseType,
- "environment": request.EnvironmentName,
- },
- })
-
- return c.JSON(http.StatusOK, adviceList)
-}
-
type schemaDiffRequestBody struct {
EngineType parser.EngineType `json:"engineType"`
SourceSchema string `json:"sourceSchema"`
@@ -235,53 +62,3 @@ func schemaDiff(c echo.Context) error {
return c.JSON(http.StatusOK, diff)
}
-
-func (s *Server) sqlCheck(
- ctx context.Context,
- dbType advisorDB.Type,
- dbCharacterSet string,
- dbCollation string,
- environmentID int,
- statement string,
- catalog catalog.Catalog,
- driver *sql.DB,
-) (advisor.Status, []advisor.Advice, error) {
- var adviceList []advisor.Advice
- policy, err := s.store.GetSQLReviewPolicy(ctx, environmentID)
- if err != nil {
- if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {
- return advisor.Success, nil, nil
- }
- return advisor.Error, nil, err
- }
-
- res, err := advisor.SQLReviewCheck(statement, policy.RuleList, advisor.SQLReviewCheckContext{
- Charset: dbCharacterSet,
- Collation: dbCollation,
- DbType: dbType,
- Catalog: catalog,
- Driver: driver,
- Context: ctx,
- })
- if err != nil {
- return advisor.Error, nil, err
- }
-
- adviceLevel := advisor.Success
- for _, advice := range res {
- switch advice.Status {
- case advisor.Warn:
- if adviceLevel != advisor.Error {
- adviceLevel = advisor.Warn
- }
- case advisor.Error:
- adviceLevel = advisor.Error
- case advisor.Success:
- continue
- }
-
- adviceList = append(adviceList, advice)
- }
-
- return adviceLevel, adviceList, nil
-}
diff --git a/backend/server/server.go b/backend/server/server.go
index a5dbc69c67..359cab67ba 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -17,7 +17,6 @@ import (
// embed will embeds the acl policy.
_ "embed"
- "github.com/blang/semver/v4"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
"github.com/google/uuid"
@@ -169,9 +168,6 @@ type Server struct {
licenseService enterpriseAPI.LicenseService
- // SchemaVersion is the bytebase's schema version
- SchemaVersion *semver.Version
-
profile config.Profile
e *echo.Echo
grpcServer *grpc.Server
@@ -327,11 +323,9 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
if profile.Readonly {
slog.Info("Database is opened in readonly mode. Skip migration and demo data setup.")
} else {
- metadataVersion, err := migrator.MigrateSchema(ctx, storeDB, !profile.UseEmbedDB(), s.pgBinDir, profile.DemoName, profile.Version, profile.Mode)
- if err != nil {
+ if _, err := migrator.MigrateSchema(ctx, storeDB, !profile.UseEmbedDB(), s.pgBinDir, profile.DemoName, profile.Version, profile.Mode); err != nil {
return nil, err
}
- s.SchemaVersion = metadataVersion
}
s.stateCfg = &state.State{
@@ -545,7 +539,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
// Register healthz endpoint.
e.GET("/healthz", func(c echo.Context) error {
- return c.String(http.StatusOK, "OK!\n")
+ return c.String(http.StatusOK, "OK")
})
// Setup the gRPC and grpc-gateway.
@@ -738,8 +732,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
return s, nil
}
-func (s *Server) registerOpenAPIRoutes(e *echo.Echo) {
- e.POST("/v1/sql/advise", s.sqlCheckController)
+func (*Server) registerOpenAPIRoutes(e *echo.Echo) {
e.POST("/v1/sql/schema/diff", schemaDiff)
}
diff --git a/backend/server/task.go b/backend/server/task.go
index 712565020f..f332532017 100644
--- a/backend/server/task.go
+++ b/backend/server/task.go
@@ -21,90 +21,6 @@ import (
)
func (s *Server) registerTaskRoutes(g *echo.Group) {
- g.PATCH("/pipeline/:pipelineID/task/all", func(c echo.Context) error {
- ctx := c.Request().Context()
- pipelineID, err := strconv.Atoi(c.Param("pipelineID"))
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Pipeline ID is not a number: %s", c.Param("pipelineID"))).SetInternal(err)
- }
-
- taskPatch := &api.TaskPatch{
- UpdaterID: c.Get(getPrincipalIDContextKey()).(int),
- }
- if err := jsonapi.UnmarshalPayload(c.Request().Body, taskPatch); err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, "Malformed update task request").SetInternal(err)
- }
-
- if taskPatch.EarliestAllowedTs != nil {
- if err := s.licenseService.IsFeatureEnabled(api.FeatureTaskScheduleTime); err != nil {
- return echo.NewHTTPError(http.StatusForbidden, err.Error())
- }
- }
-
- issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{PipelineID: &pipelineID})
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue with pipeline ID: %d", pipelineID)).SetInternal(err)
- }
- if issue == nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Issue not found with pipelineID: %d", pipelineID))
- }
-
- tasks, err := s.store.ListTasks(ctx, &api.TaskFind{PipelineID: issue.PipelineUID})
- if err != nil {
- return err
- }
- for _, task := range tasks {
- if taskPatch.EarliestAllowedTs != nil {
- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find instance %d", task.InstanceID)).SetInternal(err)
- }
- if instance == nil {
- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Cannot found the find instance %d", task.InstanceID))
- }
- if err := s.licenseService.IsFeatureEnabledForInstance(api.FeatureTaskScheduleTime, instance); err != nil {
- return echo.NewHTTPError(http.StatusForbidden, err.Error())
- }
- }
- // Skip gh-ost cutover task as this task has no statement.
- if task.Type == api.TaskDatabaseSchemaUpdateGhostCutover {
- continue
- }
- taskPatch := *taskPatch
- taskPatch.ID = task.ID
- // TODO(d): patch tasks in batch.
- if err := patchTask(ctx, s.store, s.activityManager, task, &taskPatch, issue); err != nil {
- return err
- }
- }
-
- // dismiss stale review, re-find the approval template
- if taskPatch.SheetID != nil {
- payload := &storepb.IssuePayload{}
- if err := protojson.Unmarshal([]byte(issue.Payload), payload); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "failed to unmarshal").SetInternal(err)
- }
- payload.Approval = &storepb.IssuePayloadApproval{
- ApprovalFindingDone: false,
- }
- payloadBytes, err := protojson.Marshal(payload)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal issue payload").SetInternal(err)
- }
- payloadStr := string(payloadBytes)
- issue, err := s.store.UpdateIssueV2(ctx, issue.UID, &store.UpdateIssueMessage{
- Payload: &payloadStr,
- }, api.SystemBotID)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update issue").SetInternal(err)
- }
- s.stateCfg.ApprovalFinding.Store(issue.UID, issue)
- }
-
- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
- return nil
- })
-
g.PATCH("/pipeline/:pipelineID/task/:taskID", func(c echo.Context) error {
ctx := c.Request().Context()
taskID, err := strconv.Atoi(c.Param("taskID"))
diff --git a/backend/store/issue.go b/backend/store/issue.go
index c0416ad3a8..e552ef4b55 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -220,10 +220,6 @@ func (s *Store) composePipeline(ctx context.Context, pipeline *PipelineMessage)
if err != nil {
return nil, err
}
- taskCheckRuns, err := s.ListTaskCheckRuns(ctx, &TaskCheckRunFind{PipelineID: &pipeline.ID})
- if err != nil {
- return nil, err
- }
var composedTasks []*api.Task
for _, task := range tasks {
composedTask := task.toTask()
@@ -254,24 +250,6 @@ func (s *Store) composePipeline(ctx context.Context, pipeline *PipelineMessage)
composedTask.TaskRunList = append(composedTask.TaskRunList, composedTaskRun)
}
}
- for _, taskCheckRun := range taskCheckRuns {
- if taskCheckRun.TaskID == task.ID {
- composedTaskCheckRun := taskCheckRun.toTaskCheckRun()
- creator, err := s.GetPrincipalByID(ctx, taskCheckRun.CreatorID)
- if err != nil {
- return nil, err
- }
- composedTaskCheckRun.Creator = creator
- updater, err := s.GetPrincipalByID(ctx, taskCheckRun.UpdaterID)
- if err != nil {
- return nil, err
- }
- composedTaskCheckRun.Updater = updater
- composedTaskCheckRun.CreatedTs = taskCheckRun.CreatedTs
- composedTaskCheckRun.UpdatedTs = taskCheckRun.UpdatedTs
- composedTask.TaskCheckRunList = append(composedTask.TaskCheckRunList, composedTaskCheckRun)
- }
- }
instance, err := s.GetInstanceByID(ctx, task.InstanceID)
if err != nil {
diff --git a/backend/store/task.go b/backend/store/task.go
index 65e2b0a103..2e834777a5 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -29,9 +29,8 @@ type TaskMessage struct {
StageID int
InstanceID int
// Could be empty for creating database task when the task isn't yet completed successfully.
- DatabaseID *int
- TaskRunRawList []*TaskRunMessage
- TaskCheckRunRawList []*TaskCheckRunMessage
+ DatabaseID *int
+ TaskRunRawList []*TaskRunMessage
// Domain specific fields
Name string
@@ -138,13 +137,6 @@ func (s *Store) composeTask(ctx context.Context, task *TaskMessage) (*api.Task,
if err != nil {
return nil, err
}
- taskCheckRunFind := &TaskCheckRunFind{
- TaskID: &composedTask.ID,
- }
- taskCheckRunRawList, err := s.ListTaskCheckRuns(ctx, taskCheckRunFind)
- if err != nil {
- return nil, err
- }
for _, taskRunRaw := range taskRunRawList {
taskRun := taskRunRaw.toTaskRun()
creator, err := s.GetPrincipalByID(ctx, taskRun.CreatorID)
@@ -160,22 +152,6 @@ func (s *Store) composeTask(ctx context.Context, task *TaskMessage) (*api.Task,
taskRun.Updater = updater
composedTask.TaskRunList = append(composedTask.TaskRunList, taskRun)
}
- for _, taskCheckRunRaw := range taskCheckRunRawList {
- composedTaskCheckRun := taskCheckRunRaw.toTaskCheckRun()
- creator, err := s.GetPrincipalByID(ctx, taskCheckRunRaw.CreatorID)
- if err != nil {
- return nil, err
- }
- composedTaskCheckRun.Creator = creator
- updater, err := s.GetPrincipalByID(ctx, taskCheckRunRaw.UpdaterID)
- if err != nil {
- return nil, err
- }
- composedTaskCheckRun.Updater = updater
- composedTaskCheckRun.CreatedTs = taskCheckRunRaw.CreatedTs
- composedTaskCheckRun.UpdatedTs = taskCheckRunRaw.UpdatedTs
- composedTask.TaskCheckRunList = append(composedTask.TaskCheckRunList, composedTaskCheckRun)
- }
instance, err := s.GetInstanceByID(ctx, composedTask.InstanceID)
if err != nil {
diff --git a/backend/store/task_check_run.go b/backend/store/task_check_run.go
index 93aaa7672b..a612784f1d 100644
--- a/backend/store/task_check_run.go
+++ b/backend/store/task_check_run.go
@@ -41,27 +41,6 @@ type TaskCheckRunFind struct {
StatusList *[]api.TaskCheckRunStatus
}
-func (run *TaskCheckRunMessage) toTaskCheckRun() *api.TaskCheckRun {
- return &api.TaskCheckRun{
- ID: run.ID,
-
- // Standard fields
- UpdaterID: run.UpdaterID,
- UpdatedTs: run.UpdatedTs,
-
- // Related fields
- TaskID: run.TaskID,
-
- // Domain specific fields
- Status: run.Status,
- Type: run.Type,
- Code: run.Code,
- Comment: run.Comment,
- Result: run.Result,
- Payload: run.Payload,
- }
-}
-
// ListTaskCheckRuns list task check runs.
func (s *Store) ListTaskCheckRuns(ctx context.Context, find *TaskCheckRunFind) ([]*TaskCheckRunMessage, error) {
tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})