Skip to content

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

feat: impl statement type check (#7576)

p0ny7253044684b9
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 733c4a4e8e..d8f29489ff 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -161,6 +161,15 @@ func (s *RolloutService) CreatePlan(ctx context.Context, request *v1pb.CreatePla
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create plan, error: %v", err)
}
+
+ planCheckRuns, err := getPlanCheckRunsForPlan(ctx, s.store, plan)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to get plan check runs for plan, error: %v", err)
+ }
+ if err := s.store.CreatePlanCheckRuns(ctx, planCheckRuns...); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to create plan check runs, error: %v", err)
+ }
+
return convertToPlan(plan), nil
}
diff --git a/backend/api/v1/rollout_service_plan_check.go b/backend/api/v1/rollout_service_plan_check.go
index eeaccf3196..9e0597cf56 100644
--- a/backend/api/v1/rollout_service_plan_check.go
+++ b/backend/api/v1/rollout_service_plan_check.go
@@ -2,11 +2,13 @@ package v1
import (
"context"
+ "strconv"
"github.com/pkg/errors"
"github.com/bytebase/bytebase/backend/common"
api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/store"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -32,10 +34,21 @@ func getPlanCheckRunsForSpec(ctx context.Context, s *store.Store, plan *store.Pl
// TODO(p0ny): implement
case *storepb.PlanConfig_Spec_ChangeDatabaseConfig:
target := config.ChangeDatabaseConfig.Target
+
instanceID, databaseName, err := common.GetInstanceDatabaseID(target)
if err != nil {
return nil, errors.Wrapf(err, "failed to get instance database id from target %q", target)
}
+
+ _, sheetUIDStr, err := common.GetProjectResourceIDSheetID(config.ChangeDatabaseConfig.Sheet)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get sheet id from sheet name %q", config.ChangeDatabaseConfig.Sheet)
+ }
+ sheetUID, err := strconv.Atoi(sheetUIDStr)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to convert sheet id from %q", sheetUIDStr)
+ }
+
instance, err := s.GetInstanceV2(ctx, &store.FindInstanceMessage{
ResourceID: &instanceID,
})
@@ -67,8 +80,45 @@ func getPlanCheckRunsForSpec(ctx context.Context, s *store.Store, plan *store.Pl
DatabaseId: int32(database.UID),
},
})
+ if isStatementTypeCheckSupported(instance.Engine) {
+ planCheckRuns = append(planCheckRuns, &store.PlanCheckRunMessage{
+ CreatorUID: api.SystemBotID,
+ UpdaterUID: api.SystemBotID,
+ PlanUID: plan.UID,
+ Status: store.PlanCheckRunStatusRunning,
+ Type: store.PlanCheckDatabaseStatementType,
+ Config: &storepb.PlanCheckRunConfig{
+ SheetId: int32(sheetUID),
+ DatabaseId: int32(database.UID),
+ ChangeDatabaseType: convertToChangeDatabaseType(config.ChangeDatabaseConfig.Type),
+ },
+ })
+ }
case *storepb.PlanConfig_Spec_RestoreDatabaseConfig:
// TODO(p0ny): implement
}
return planCheckRuns, nil
}
+
+func convertToChangeDatabaseType(t storepb.PlanConfig_ChangeDatabaseConfig_Type) storepb.PlanCheckRunConfig_ChangeDatabaseType {
+ switch t {
+ case
+ storepb.PlanConfig_ChangeDatabaseConfig_MIGRATE,
+ storepb.PlanConfig_ChangeDatabaseConfig_MIGRATE_GHOST:
+ return storepb.PlanCheckRunConfig_DDL
+ case storepb.PlanConfig_ChangeDatabaseConfig_MIGRATE_SDL:
+ return storepb.PlanCheckRunConfig_SDL
+ case storepb.PlanConfig_ChangeDatabaseConfig_DATA:
+ return storepb.PlanCheckRunConfig_DML
+ }
+ return storepb.PlanCheckRunConfig_CHANGE_DATABASE_TYPE_UNSPECIFIED
+}
+
+func isStatementTypeCheckSupported(dbType db.Type) bool {
+ switch dbType {
+ case db.Postgres, db.TiDB, db.MySQL, db.MariaDB, db.OceanBase:
+ return true
+ default:
+ return false
+ }
+}
diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code.go
index 6ff8a500a7..b46c13b022 100644
--- a/backend/plugin/advisor/code.go
+++ b/backend/plugin/advisor/code.go
@@ -142,3 +142,8 @@ const (
func (c Code) Int() int {
return int(c)
}
+
+// Int64 returns the int64 type of code.
+func (c Code) Int64() int64 {
+ return int64(c)
+}
diff --git a/backend/runner/plancheck/database_connect_executor.go b/backend/runner/plancheck/database_connect_executor.go
index 0897034c23..e6d8e801c9 100644
--- a/backend/runner/plancheck/database_connect_executor.go
+++ b/backend/runner/plancheck/database_connect_executor.go
@@ -29,25 +29,29 @@ type DatabaseConnectExecutor struct {
}
// Run runs the executor.
-func (e *DatabaseConnectExecutor) Run(ctx context.Context, planCheckRun *store.PlanCheckRunMessage) (results []*storepb.PlanCheckRunResult_Result, err error) {
+func (e *DatabaseConnectExecutor) Run(ctx context.Context, planCheckRun *store.PlanCheckRunMessage) ([]*storepb.PlanCheckRunResult_Result, error) {
databaseID := int(planCheckRun.Config.DatabaseId)
database, err := e.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &databaseID})
if err != nil {
return nil, errors.Wrapf(err, "failed to get database ID %v", databaseID)
}
if database == nil {
- return nil, errors.Wrapf(err, "database ID not found %v", databaseID)
+ return nil, errors.Errorf("database not found %v", databaseID)
}
instance, err := e.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &database.InstanceID})
if err != nil {
return nil, errors.Wrapf(err, "failed to get instance %v", database.InstanceID)
}
+ if instance == nil {
+ return nil, errors.Errorf("instance not found %v", database.InstanceID)
+ }
driver, err := e.dbFactory.GetAdminDatabaseDriver(ctx, instance, database)
if err == nil {
err = driver.Ping(ctx)
}
if err != nil {
+ // nolint:nilerr
return []*storepb.PlanCheckRunResult_Result{
{
Status: storepb.PlanCheckRunResult_Result_ERROR,
diff --git a/backend/runner/plancheck/statement_type_executor.go b/backend/runner/plancheck/statement_type_executor.go
new file mode 100644
index 0000000000..0199a48e3d
--- /dev/null
+++ b/backend/runner/plancheck/statement_type_executor.go
@@ -0,0 +1,481 @@
+package plancheck
+
+import (
+ "context"
+ "fmt"
+
+ tidbparser "github.com/pingcap/tidb/parser"
+ tidbast "github.com/pingcap/tidb/parser/ast"
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/component/dbfactory"
+ api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/plugin/advisor"
+ "github.com/bytebase/bytebase/backend/plugin/db"
+ parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"
+ "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
+ "github.com/bytebase/bytebase/backend/runner/utils"
+ "github.com/bytebase/bytebase/backend/store"
+ backendutils "github.com/bytebase/bytebase/backend/utils"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
+)
+
+var _ Executor = (*StatementTypeExecutor)(nil)
+
+// NewStatementTypeExecutor creates a task check DML executor.
+func NewStatementTypeExecutor(store *store.Store, dbFactory *dbfactory.DBFactory) Executor {
+ return &StatementTypeExecutor{
+ store: store,
+ dbFactory: dbFactory,
+ }
+}
+
+// StatementTypeExecutor is the task check DML executor.
+type StatementTypeExecutor struct {
+ store *store.Store
+ dbFactory *dbfactory.DBFactory
+}
+
+// Run will run the task check database connector executor once.
+func (e *StatementTypeExecutor) Run(ctx context.Context, planCheckRun *store.PlanCheckRunMessage) ([]*storepb.PlanCheckRunResult_Result, error) {
+ changeType := planCheckRun.Config.ChangeDatabaseType
+ if changeType == storepb.PlanCheckRunConfig_CHANGE_DATABASE_TYPE_UNSPECIFIED {
+ return nil, errors.Errorf("change database type is unspecified")
+ }
+
+ databaseID := int(planCheckRun.Config.DatabaseId)
+ database, err := e.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &databaseID})
+ if err != nil {
+ return nil, err
+ }
+ if database == nil {
+ return nil, errors.Errorf("database not found: %d", databaseID)
+ }
+
+ instance, err := e.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &database.InstanceID})
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get instance %v", database.InstanceID)
+ }
+
+ dbSchema, err := e.store.GetDBSchema(ctx, database.UID)
+ if err != nil {
+ return nil, err
+ }
+ if dbSchema == nil {
+ return nil, errors.Errorf("database schema not found: %d", database.UID)
+ }
+
+ sheetID := int(planCheckRun.Config.SheetId)
+ sheet, err := e.store.GetSheet(ctx, &store.FindSheetMessage{UID: &sheetID}, api.SystemBotID)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get sheet %d", sheetID)
+ }
+ if sheet == nil {
+ return nil, errors.Errorf("sheet %d not found", sheetID)
+ }
+ if sheet.Size > common.MaxSheetSizeForTaskCheck {
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,
+ Code: common.Ok.Int64(),
+ Title: "Large SQL review policy is disabled",
+ Content: "",
+ },
+ }, nil
+ }
+
+ statement, err := e.store.GetSheetStatementByID(ctx, sheetID)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get sheet statement %d", sheetID)
+ }
+
+ materials := backendutils.GetSecretMapFromDatabaseMessage(database)
+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.
+ renderedStatement := backendutils.RenderStatement(statement, materials)
+
+ var results []*storepb.PlanCheckRunResult_Result
+ switch instance.Engine {
+ case db.Postgres, db.RisingWave:
+ checkResults, err := postgresqlStatementTypeCheck(renderedStatement, changeType)
+ if err != nil {
+ return nil, err
+ }
+ results = append(results, checkResults...)
+ case db.MySQL, db.TiDB, db.MariaDB, db.OceanBase:
+ checkResults, err := mysqlStatementTypeCheck(renderedStatement, dbSchema.Metadata.CharacterSet, dbSchema.Metadata.Collation, changeType)
+ if err != nil {
+ return nil, err
+ }
+ results = append(results, checkResults...)
+ if changeType == storepb.PlanCheckRunConfig_SDL {
+ sdlAdvice, err := e.mysqlSDLTypeCheck(ctx, renderedStatement, instance, database)
+ if err != nil {
+ return nil, err
+ }
+ results = append(results, sdlAdvice...)
+ }
+ default:
+ return nil, common.Errorf(common.Invalid, "invalid check statement type database type: %s", instance.Engine)
+ }
+
+ if len(results) == 0 {
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,
+ Title: "OK",
+ Content: "",
+ Code: common.Ok.Int64(),
+ Report: nil,
+ },
+ }, nil
+ }
+
+ return results, nil
+}
+
+func (e *StatementTypeExecutor) mysqlSDLTypeCheck(ctx context.Context, newSchema string, instance *store.InstanceMessage, database *store.DatabaseMessage) ([]*storepb.PlanCheckRunResult_Result, error) {
+ ddl, err := utils.ComputeDatabaseSchemaDiff(ctx, instance, database, e.dbFactory, newSchema)
+ if err != nil {
+ return nil, err
+ }
+
+ list, err := parser.SplitMultiSQL(parser.MySQL, ddl)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to split SQL")
+ }
+
+ var results []*storepb.PlanCheckRunResult_Result
+ for _, stmt := range list {
+ if parser.IsTiDBUnsupportDDLStmt(stmt.Text) {
+ continue
+ }
+ nodeList, _, err := tidbparser.New().Parse(stmt.Text, "", "")
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse schema %q", stmt.Text)
+ }
+ if len(nodeList) != 1 {
+ return nil, errors.Errorf("Expect one statement after splitting but found %d", len(nodeList))
+ }
+
+ switch node := nodeList[0].(type) {
+ case *tidbast.DropTableStmt:
+ for _, table := range node.Tables {
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropTable.Int64(),
+ Title: "Plan to drop table",
+ Content: fmt.Sprintf("Plan to drop table `%s`", table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ }
+ case *tidbast.DropIndexStmt:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropIndex.Int64(),
+ Title: "Plan to drop index",
+ Content: fmt.Sprintf("Plan to drop index `%s` on table `%s`", node.IndexName, node.Table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ case *tidbast.AlterTableStmt:
+ for _, spec := range node.Specs {
+ switch spec.Tp {
+ case tidbast.AlterTableDropColumn:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropColumn.Int64(),
+ Title: "Plan to drop column",
+ Content: fmt.Sprintf("Plan to drop column `%s` on table `%s`", spec.OldColumnName.Name.O, node.Table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ case tidbast.AlterTableDropPrimaryKey:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropPrimaryKey.Int64(),
+ Title: "Plan to drop primary key",
+ Content: fmt.Sprintf("Plan to drop primary key on table `%s`", node.Table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ case tidbast.AlterTableDropForeignKey:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropForeignKey.Int64(),
+ Title: "Plan to drop foreign key",
+ Content: fmt.Sprintf("Plan to drop foreign key `%s` on table `%s`", spec.Name, node.Table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ case tidbast.AlterTableDropCheck:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.TaskTypeDropCheck.Int64(),
+ Title: "Plan to drop check constraint",
+ Content: fmt.Sprintf("Plan to drop check constraint `%s` on table `%s`", spec.Constraint.Name, node.Table.Name.O),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: int64(stmt.LastLine),
+ Detail: "",
+ Code: 0,
+ },
+ },
+ })
+ }
+ }
+ }
+ }
+ return results, nil
+}
+
+func mysqlCreateAndDropDatabaseCheck(nodeList []tidbast.StmtNode) []*storepb.PlanCheckRunResult_Result {
+ var results []*storepb.PlanCheckRunResult_Result
+ for _, node := range nodeList {
+ switch node.(type) {
+ case *tidbast.DropDatabaseStmt:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Code: common.TaskTypeDropDatabase.Int64(),
+ Title: "Cannot drop database",
+ Content: fmt.Sprintf(`The statement "%s" drops database`, node.Text()),
+ })
+ case *tidbast.CreateDatabaseStmt:
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Code: common.TaskTypeCreateDatabase.Int64(),
+ Title: "Cannot create database",
+ Content: fmt.Sprintf(`The statement "%s" creates database`, node.Text()),
+ })
+ }
+ }
+
+ return results
+}
+
+func mysqlStatementTypeCheck(statement string, charset string, collation string, changeType storepb.PlanCheckRunConfig_ChangeDatabaseType) ([]*storepb.PlanCheckRunResult_Result, error) {
+ // Due to the limitation of TiDB parser, we should split the multi-statement into single statements, and extract
+ // the TiDB unsupported statements, otherwise, the parser will panic or return the error.
+ unsupportStmt, supportStmt, err := parser.ExtractTiDBUnsupportStmts(statement)
+ if err != nil {
+ // nolint:nilerr
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Title: "Syntax error",
+ Content: err.Error(),
+ Code: 0,
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: 0,
+ Detail: "",
+ Code: advisor.StatementSyntaxError.Int64(),
+ },
+ },
+ },
+ }, nil
+ }
+ // TODO(zp): We regard the DELIMITER statement as a DDL statement here.
+ // But we should ban the DELIMITER statement because go-sql-driver doesn't support it.
+ hasUnsupportDDL := len(unsupportStmt) > 0
+
+ p := tidbparser.New()
+ // To support MySQL8 window function syntax.
+ // See https://github.com/bytebase/bytebase/issues/175.
+ p.EnableWindowFunc(true)
+
+ stmts, _, err := p.Parse(supportStmt, charset, collation)
+ if err != nil {
+ // nolint: nilerr
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Title: "Syntax error",
+ Content: err.Error(),
+ Code: 0,
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: 0,
+ Detail: "",
+ Code: advisor.StatementSyntaxError.Int64(),
+ },
+ },
+ },
+ }, nil
+ }
+
+ if err != nil {
+ // nolint: nilerr
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Title: "Syntax error",
+ Content: err.Error(),
+ Code: 0,
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: 0,
+ Detail: "",
+ Code: advisor.StatementSyntaxError.Int64(),
+ },
+ },
+ },
+ }, nil
+ }
+
+ var results []*storepb.PlanCheckRunResult_Result
+
+ // Disallow CREATE/DROP DATABASE statements.
+ results = append(results, mysqlCreateAndDropDatabaseCheck(stmts)...)
+
+ switch changeType {
+ case storepb.PlanCheckRunConfig_DML:
+ for _, node := range stmts {
+ _, isDDL := node.(tidbast.DDLNode)
+ // We only want to disallow DDL statements in CHANGE DATA.
+ // We need to run some common statements, e.g. COMMIT.
+ if isDDL || hasUnsupportDDL {
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Title: "Data change can only run DML",
+ Content: fmt.Sprintf("\"%s\" is not DML", node.Text()),
+ Code: common.TaskTypeNotDML.Int64(),
+ Report: nil,
+ })
+ }
+ }
+ case storepb.PlanCheckRunConfig_DDL, storepb.PlanCheckRunConfig_SDL:
+ for _, node := range stmts {
+ _, isDML := node.(tidbast.DMLNode)
+ _, isExplain := node.(*tidbast.ExplainStmt)
+ if isDML || isExplain {
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Title: "Alter schema can only run DDL",
+ Content: fmt.Sprintf("\"%s\" is not DDL", node.Text()),
+ Code: common.TaskTypeNotDDL.Int64(),
+ Report: nil,
+ })
+ }
+ }
+ default:
+ return nil, common.Errorf(common.Invalid, "invalid check statement type task type: %s", changeType)
+ }
+
+ return results, nil
+}
+
+func postgresqlCreateAndDropDatabaseCheck(nodeList []ast.Node) []*storepb.PlanCheckRunResult_Result {
+ var result []*storepb.PlanCheckRunResult_Result
+ for _, node := range nodeList {
+ switch node.(type) {
+ case *ast.DropDatabaseStmt:
+ result = append(result, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Code: common.TaskTypeDropDatabase.Int64(),
+ Title: "Cannot drop database",
+ Content: fmt.Sprintf(`The statement "%s" drops database`, node.Text()),
+ Report: nil,
+ })
+ case *ast.CreateDatabaseStmt:
+ result = append(result, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Code: common.TaskTypeCreateDatabase.Int64(),
+ Title: "Cannot create database",
+ Content: fmt.Sprintf(`The statement "%s" creates database`, node.Text()),
+ Report: nil,
+ })
+ }
+ }
+ return result
+}
+
+func postgresqlStatementTypeCheck(statement string, changeType storepb.PlanCheckRunConfig_ChangeDatabaseType) ([]*storepb.PlanCheckRunResult_Result, error) {
+ stmts, err := parser.Parse(parser.Postgres, parser.ParseContext{}, statement)
+ if err != nil {
+ // nolint:nilerr
+ return []*storepb.PlanCheckRunResult_Result{
+ {
+ Status: storepb.PlanCheckRunResult_Result_ERROR,
+ Code: 0,
+ Title: "Syntax error",
+ Content: err.Error(),
+ Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
+ SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
+ Line: 0,
+ Detail: "",
+ Code: advisor.StatementSyntaxError.Int64(),
+ },
+ },
+ },
+ }, nil
+ }
+
+ var results []*storepb.PlanCheckRunResult_Result
+
+ // Disallow CREATE/DROP DATABASE statements.
+ results = append(results, postgresqlCreateAndDropDatabaseCheck(stmts)...)
+
+ switch changeType {
+ case storepb.PlanCheckRunConfig_DML:
+ for _, node := range stmts {
+ _, isDDL := node.(ast.DDLNode)
+ // We only want to disallow DDL statements in CHANGE DATA.
+ // We need to run some common statements, e.g. COMMIT.
+ if isDDL {
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Title: "Data change can only run DML",
+ Content: fmt.Sprintf("\"%s\" is not DML", node.Text()),
+ Code: common.TaskTypeNotDML.Int64(),
+ Report: nil,
+ })
+ }
+ }
+ case storepb.PlanCheckRunConfig_DDL, storepb.PlanCheckRunConfig_SDL:
+ for _, node := range stmts {
+ _, isDML := node.(ast.DMLNode)
+ _, isSelect := node.(*ast.SelectStmt)
+ _, isExplain := node.(*ast.ExplainStmt)
+ if isDML || isSelect || isExplain {
+ results = append(results, &storepb.PlanCheckRunResult_Result{
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Title: "Alter schema can only run DDL",
+ Content: fmt.Sprintf("\"%s\" is not DDL", node.Text()),
+ Code: common.TaskTypeNotDDL.Int64(),
+ Report: nil,
+ })
+ }
+ }
+ default:
+ return nil, common.Errorf(common.Invalid, "invalid check statement type task type: %s", changeType)
+ }
+
+ return results, nil
+}
diff --git a/backend/server/server.go b/backend/server/server.go
index 1842ddd43d..36cdc15b5e 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -510,6 +510,8 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.PlanCheckScheduler = plancheck.NewScheduler(storeInstance, s.licenseService, s.stateCfg)
databaseConnectExecutor := plancheck.NewDatabaseConnectExecutor(storeInstance, s.dbFactory)
s.PlanCheckScheduler.Register(store.PlanCheckDatabaseConnect, databaseConnectExecutor)
+ statementTypeExecutor := plancheck.NewStatementTypeExecutor(storeInstance, s.dbFactory)
+ s.PlanCheckScheduler.Register(store.PlanCheckDatabaseStatementType, statementTypeExecutor)
}
// Anomaly scanner
diff --git a/frontend/src/types/proto/store/plan_check_run.ts b/frontend/src/types/proto/store/plan_check_run.ts
index 999b54cdf0..6b9a37a2f8 100644
--- a/frontend/src/types/proto/store/plan_check_run.ts
+++ b/frontend/src/types/proto/store/plan_check_run.ts
@@ -7,6 +7,52 @@ export const protobufPackage = "bytebase.store";
export interface PlanCheckRunConfig {
sheetId: number;
databaseId: number;
+ changeDatabaseType: PlanCheckRunConfig_ChangeDatabaseType;
+}
+
+export enum PlanCheckRunConfig_ChangeDatabaseType {
+ CHANGE_DATABASE_TYPE_UNSPECIFIED = 0,
+ DDL = 1,
+ DML = 2,
+ SDL = 3,
+ UNRECOGNIZED = -1,
+}
+
+export function planCheckRunConfig_ChangeDatabaseTypeFromJSON(object: any): PlanCheckRunConfig_ChangeDatabaseType {
+ switch (object) {
+ case 0:
+ case "CHANGE_DATABASE_TYPE_UNSPECIFIED":
+ return PlanCheckRunConfig_ChangeDatabaseType.CHANGE_DATABASE_TYPE_UNSPECIFIED;
+ case 1:
+ case "DDL":
+ return PlanCheckRunConfig_ChangeDatabaseType.DDL;
+ case 2:
+ case "DML":
+ return PlanCheckRunConfig_ChangeDatabaseType.DML;
+ case 3:
+ case "SDL":
+ return PlanCheckRunConfig_ChangeDatabaseType.SDL;
+ case -1:
+ case "UNRECOGNIZED":
+ default:
+ return PlanCheckRunConfig_ChangeDatabaseType.UNRECOGNIZED;
+ }
+}
+
+export function planCheckRunConfig_ChangeDatabaseTypeToJSON(object: PlanCheckRunConfig_ChangeDatabaseType): string {
+ switch (object) {
+ case PlanCheckRunConfig_ChangeDatabaseType.CHANGE_DATABASE_TYPE_UNSPECIFIED:
+ return "CHANGE_DATABASE_TYPE_UNSPECIFIED";
+ case PlanCheckRunConfig_ChangeDatabaseType.DDL:
+ return "DDL";
+ case PlanCheckRunConfig_ChangeDatabaseType.DML:
+ return "DML";
+ case PlanCheckRunConfig_ChangeDatabaseType.SDL:
+ return "SDL";
+ case PlanCheckRunConfig_ChangeDatabaseType.UNRECOGNIZED:
+ default:
+ return "UNRECOGNIZED";
+ }
}
export interface PlanCheckRunResult {
@@ -81,7 +127,7 @@ export interface PlanCheckRunResult_Result_SqlReviewReport {
}
function createBasePlanCheckRunConfig(): PlanCheckRunConfig {
- return { sheetId: 0, databaseId: 0 };
+ return { sheetId: 0, databaseId: 0, changeDatabaseType: 0 };
}
export const PlanCheckRunConfig = {
@@ -92,6 +138,9 @@ export const PlanCheckRunConfig = {
if (message.databaseId !== 0) {
writer.uint32(16).int32(message.databaseId);
}
+ if (message.changeDatabaseType !== 0) {
+ writer.uint32(24).int32(message.changeDatabaseType);
+ }
return writer;
},
@@ -116,6 +165,13 @@ export const PlanCheckRunConfig = {
message.databaseId = reader.int32();
continue;
+ case 3:
+ if (tag !== 24) {
+ break;
+ }
+
+ message.changeDatabaseType = reader.int32() as any;
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -129,6 +185,9 @@ export const PlanCheckRunConfig = {
return {
sheetId: isSet(object.sheetId) ? Number(object.sheetId) : 0,
databaseId: isSet(object.databaseId) ? Number(object.databaseId) : 0,
+ changeDatabaseType: isSet(object.changeDatabaseType)
+ ? planCheckRunConfig_ChangeDatabaseTypeFromJSON(object.changeDatabaseType)
+ : 0,
};
},
@@ -136,6 +195,8 @@ export const PlanCheckRunConfig = {
const obj: any = {};
message.sheetId !== undefined && (obj.sheetId = Math.round(message.sheetId));
message.databaseId !== undefined && (obj.databaseId = Math.round(message.databaseId));
+ message.changeDatabaseType !== undefined &&
+ (obj.changeDatabaseType = planCheckRunConfig_ChangeDatabaseTypeToJSON(message.changeDatabaseType));
return obj;
},
@@ -147,6 +208,7 @@ export const PlanCheckRunConfig = {
const message = createBasePlanCheckRunConfig();
message.sheetId = object.sheetId ?? 0;
message.databaseId = object.databaseId ?? 0;
+ message.changeDatabaseType = object.changeDatabaseType ?? 0;
return message;
},
};
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 52807199b9..7d9ee2b3dd 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -112,6 +112,7 @@
- [PlanCheckRunResult.Result.SqlReviewReport](#bytebase-store-PlanCheckRunResult-Result-SqlReviewReport)
- [PlanCheckRunResult.Result.SqlSummaryReport](#bytebase-store-PlanCheckRunResult-Result-SqlSummaryReport)
+ - [PlanCheckRunConfig.ChangeDatabaseType](#bytebase-store-PlanCheckRunConfig-ChangeDatabaseType)
- [PlanCheckRunResult.Result.Status](#bytebase-store-PlanCheckRunResult-Result-Status)
- [store/policy.proto](#store_policy-proto)
@@ -1652,6 +1653,7 @@ Type is the database change type.
| ----- | ---- | ----- | ----------- |
| sheet_id | [int32](#int32) | | |
| database_id | [int32](#int32) | | |
+| change_database_type | [PlanCheckRunConfig.ChangeDatabaseType](#bytebase-store-PlanCheckRunConfig-ChangeDatabaseType) | | |
@@ -1729,6 +1731,20 @@ Type is the database change type.
+<a name="bytebase-store-PlanCheckRunConfig-ChangeDatabaseType"></a>
+
+### PlanCheckRunConfig.ChangeDatabaseType
+
+
+| Name | Number | Description |
+| ---- | ------ | ----------- |
+| CHANGE_DATABASE_TYPE_UNSPECIFIED | 0 | |
+| DDL | 1 | |
+| DML | 2 | |
+| SDL | 3 | |
+
+
+
<a name="bytebase-store-PlanCheckRunResult-Result-Status"></a>
### PlanCheckRunResult.Result.Status
diff --git a/proto/generated-go/store/plan_check_run.pb.go b/proto/generated-go/store/plan_check_run.pb.go
index d7f118145f..a9742d54a1 100644
--- a/proto/generated-go/store/plan_check_run.pb.go
+++ b/proto/generated-go/store/plan_check_run.pb.go
@@ -20,6 +20,58 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
+type PlanCheckRunConfig_ChangeDatabaseType int32
+
+const (
+ PlanCheckRunConfig_CHANGE_DATABASE_TYPE_UNSPECIFIED PlanCheckRunConfig_ChangeDatabaseType = 0
+ PlanCheckRunConfig_DDL PlanCheckRunConfig_ChangeDatabaseType = 1
+ PlanCheckRunConfig_DML PlanCheckRunConfig_ChangeDatabaseType = 2
+ PlanCheckRunConfig_SDL PlanCheckRunConfig_ChangeDatabaseType = 3
+)
+
+// Enum value maps for PlanCheckRunConfig_ChangeDatabaseType.
+var (
+ PlanCheckRunConfig_ChangeDatabaseType_name = map[int32]string{
+ 0: "CHANGE_DATABASE_TYPE_UNSPECIFIED",
+ 1: "DDL",
+ 2: "DML",
+ 3: "SDL",
+ }
+ PlanCheckRunConfig_ChangeDatabaseType_value = map[string]int32{
+ "CHANGE_DATABASE_TYPE_UNSPECIFIED": 0,
+ "DDL": 1,
+ "DML": 2,
+ "SDL": 3,
+ }
+)
+
+func (x PlanCheckRunConfig_ChangeDatabaseType) Enum() *PlanCheckRunConfig_ChangeDatabaseType {
+ p := new(PlanCheckRunConfig_ChangeDatabaseType)
+ *p = x
+ return p
+}
+
+func (x PlanCheckRunConfig_ChangeDatabaseType) String() string {
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (PlanCheckRunConfig_ChangeDatabaseType) Descriptor() protoreflect.EnumDescriptor {
+ return file_store_plan_check_run_proto_enumTypes[0].Descriptor()
+}
+
+func (PlanCheckRunConfig_ChangeDatabaseType) Type() protoreflect.EnumType {
+ return &file_store_plan_check_run_proto_enumTypes[0]
+}
+
+func (x PlanCheckRunConfig_ChangeDatabaseType) Number() protoreflect.EnumNumber {
+ return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use PlanCheckRunConfig_ChangeDatabaseType.Descriptor instead.
+func (PlanCheckRunConfig_ChangeDatabaseType) EnumDescriptor() ([]byte, []int) {
+ return file_store_plan_check_run_proto_rawDescGZIP(), []int{0, 0}
+}
+
type PlanCheckRunResult_Result_Status int32
const (
@@ -56,11 +108,11 @@ func (x PlanCheckRunResult_Result_Status) String() string {
}
func (PlanCheckRunResult_Result_Status) Descriptor() protoreflect.EnumDescriptor {
- return file_store_plan_check_run_proto_enumTypes[0].Descriptor()
+ return file_store_plan_check_run_proto_enumTypes[1].Descriptor()
}
func (PlanCheckRunResult_Result_Status) Type() protoreflect.EnumType {
- return &file_store_plan_check_run_proto_enumTypes[0]
+ return &file_store_plan_check_run_proto_enumTypes[1]
}
func (x PlanCheckRunResult_Result_Status) Number() protoreflect.EnumNumber {
@@ -77,8 +129,9 @@ type PlanCheckRunConfig struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- SheetId int32 `protobuf:"varint,1,opt,name=sheet_id,json=sheetId,proto3" json:"sheet_id,omitempty"`
- DatabaseId int32 `protobuf:"varint,2,opt,name=database_id,json=databaseId,proto3" json:"database_id,omitempty"`
+ SheetId int32 `protobuf:"varint,1,opt,name=sheet_id,json=sheetId,proto3" json:"sheet_id,omitempty"`
+ DatabaseId int32 `protobuf:"varint,2,opt,name=database_id,json=databaseId,proto3" json:"database_id,omitempty"`
+ ChangeDatabaseType PlanCheckRunConfig_ChangeDatabaseType `protobuf:"varint,3,opt,name=change_database_type,json=changeDatabaseType,proto3,enum=bytebase.store.PlanCheckRunConfig_ChangeDatabaseType" json:"change_database_type,omitempty"`
}
func (x *PlanCheckRunConfig) Reset() {
@@ -127,6 +180,13 @@ func (x *PlanCheckRunConfig) GetDatabaseId() int32 {
return 0
}
+func (x *PlanCheckRunConfig) GetChangeDatabaseType() PlanCheckRunConfig_ChangeDatabaseType {
+ if x != nil {
+ return x.ChangeDatabaseType
+ }
+ return PlanCheckRunConfig_CHANGE_DATABASE_TYPE_UNSPECIFIED
+}
+
type PlanCheckRunResult struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -419,60 +479,73 @@ var File_store_plan_check_run_proto protoreflect.FileDescriptor
var file_store_plan_check_run_proto_rawDesc = []byte{
0x0a, 0x1a, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x70, 0x6c, 0x61, 0x6e, 0x5f, 0x63, 0x68, 0x65,
0x63, 0x6b, 0x5f, 0x72, 0x75, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x62, 0x79,
- 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x22, 0x50, 0x0a, 0x12,
- 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6e, 0x66,
- 0x69, 0x67, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x68, 0x65, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01,
- 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x68, 0x65, 0x65, 0x74, 0x49, 0x64, 0x12, 0x1f, 0x0a,
- 0x0b, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
- 0x28, 0x05, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x49, 0x64, 0x22, 0xe1,
- 0x05, 0x0a, 0x12, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52,
- 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x43, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73,
- 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,
+ 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x22, 0x90, 0x02, 0x0a,
+ 0x12, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6e,
+ 0x66, 0x69, 0x67, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x68, 0x65, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18,
+ 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x68, 0x65, 0x65, 0x74, 0x49, 0x64, 0x12, 0x1f,
+ 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20,
+ 0x01, 0x28, 0x05, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x49, 0x64, 0x12,
+ 0x67, 0x0a, 0x14, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61,
+ 0x73, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x35, 0x2e,
+ 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50,
+ 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69,
+ 0x67, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
+ 0x54, 0x79, 0x70, 0x65, 0x52, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61,
+ 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x55, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x6e,
+ 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24,
+ 0x0a, 0x20, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x42, 0x41, 0x53,
+ 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49,
+ 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x44, 0x4c, 0x10, 0x01, 0x12, 0x07, 0x0a,
+ 0x03, 0x44, 0x4d, 0x4c, 0x10, 0x02, 0x12, 0x07, 0x0a, 0x03, 0x53, 0x44, 0x4c, 0x10, 0x03, 0x22,
+ 0xe1, 0x05, 0x0a, 0x12, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e,
+ 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x43, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
+ 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
+ 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65,
+ 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75,
+ 0x6c, 0x74, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x65,
+ 0x72, 0x72, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f,
+ 0x72, 0x1a, 0xef, 0x04, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x48, 0x0a, 0x06,
+ 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x30, 0x2e, 0x62,
+ 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x6c,
+ 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74,
+ 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06,
+ 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18,
+ 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07,
+ 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,
+ 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04,
+ 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x6a, 0x0a, 0x12, 0x73, 0x71,
+ 0x6c, 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74,
+ 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x3a, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,
0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63,
0x6b, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c,
- 0x74, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72,
- 0x72, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72,
- 0x1a, 0xef, 0x04, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x48, 0x0a, 0x06, 0x73,
- 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x30, 0x2e, 0x62, 0x79,
- 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x6c, 0x61,
- 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e,
- 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73,
- 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x02,
- 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63,
- 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f,
- 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20,
- 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x6a, 0x0a, 0x12, 0x73, 0x71, 0x6c,
- 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x18,
- 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x3a, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
- 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b,
- 0x52, 0x75, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74,
- 0x2e, 0x53, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, 0x6f, 0x72,
- 0x74, 0x48, 0x00, 0x52, 0x10, 0x73, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52,
- 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x67, 0x0a, 0x11, 0x73, 0x71, 0x6c, 0x5f, 0x72, 0x65, 0x76,
- 0x69, 0x65, 0x77, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b,
- 0x32, 0x39, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72,
- 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52, 0x65,
- 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x53, 0x71, 0x6c, 0x52,
- 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x00, 0x52, 0x0f, 0x73,
- 0x71, 0x6c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x5e,
- 0x0a, 0x10, 0x53, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, 0x6f,
- 0x72, 0x74, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x5f,
- 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x74,
- 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x66, 0x66,
- 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03,
- 0x52, 0x0c, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x77, 0x73, 0x1a, 0x51,
- 0x0a, 0x0f, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f, 0x72,
- 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
- 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18,
- 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x12, 0x0a,
- 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64,
- 0x65, 0x22, 0x45, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12, 0x53,
- 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45,
- 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x0b,
- 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x53,
- 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x03, 0x42, 0x08, 0x0a, 0x06, 0x72, 0x65, 0x70, 0x6f,
- 0x72, 0x74, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d,
- 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+ 0x74, 0x2e, 0x53, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, 0x6f,
+ 0x72, 0x74, 0x48, 0x00, 0x52, 0x10, 0x73, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79,
+ 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x67, 0x0a, 0x11, 0x73, 0x71, 0x6c, 0x5f, 0x72, 0x65,
+ 0x76, 0x69, 0x65, 0x77, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28,
+ 0x0b, 0x32, 0x39, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f,
+ 0x72, 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x6e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x75, 0x6e, 0x52,
+ 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x53, 0x71, 0x6c,
+ 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x00, 0x52, 0x0f,
+ 0x73, 0x71, 0x6c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a,
+ 0x5e, 0x0a, 0x10, 0x53, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70,
+ 0x6f, 0x72, 0x74, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74,
+ 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x61,
+ 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x66,
+ 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28,
+ 0x03, 0x52, 0x0c, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x77, 0x73, 0x1a,
+ 0x51, 0x0a, 0x0f, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52, 0x65, 0x70, 0x6f,
+ 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
+ 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c,
+ 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x12,
+ 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f,
+ 0x64, 0x65, 0x22, 0x45, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12,
+ 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49,
+ 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12,
+ 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07,
+ 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x03, 0x42, 0x08, 0x0a, 0x06, 0x72, 0x65, 0x70,
+ 0x6f, 0x72, 0x74, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64,
+ 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+ 0x33,
}
var (
@@ -487,26 +560,28 @@ func file_store_plan_check_run_proto_rawDescGZIP() []byte {
return file_store_plan_check_run_proto_rawDescData
}
-var file_store_plan_check_run_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
+var file_store_plan_check_run_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_store_plan_check_run_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_store_plan_check_run_proto_goTypes = []interface{}{
- (PlanCheckRunResult_Result_Status)(0), // 0: bytebase.store.PlanCheckRunResult.Result.Status
- (*PlanCheckRunConfig)(nil), // 1: bytebase.store.PlanCheckRunConfig
- (*PlanCheckRunResult)(nil), // 2: bytebase.store.PlanCheckRunResult
- (*PlanCheckRunResult_Result)(nil), // 3: bytebase.store.PlanCheckRunResult.Result
- (*PlanCheckRunResult_Result_SqlSummaryReport)(nil), // 4: bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport
- (*PlanCheckRunResult_Result_SqlReviewReport)(nil), // 5: bytebase.store.PlanCheckRunResult.Result.SqlReviewReport
+ (PlanCheckRunConfig_ChangeDatabaseType)(0), // 0: bytebase.store.PlanCheckRunConfig.ChangeDatabaseType
+ (PlanCheckRunResult_Result_Status)(0), // 1: bytebase.store.PlanCheckRunResult.Result.Status
+ (*PlanCheckRunConfig)(nil), // 2: bytebase.store.PlanCheckRunConfig
+ (*PlanCheckRunResult)(nil), // 3: bytebase.store.PlanCheckRunResult
+ (*PlanCheckRunResult_Result)(nil), // 4: bytebase.store.PlanCheckRunResult.Result
+ (*PlanCheckRunResult_Result_SqlSummaryReport)(nil), // 5: bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport
+ (*PlanCheckRunResult_Result_SqlReviewReport)(nil), // 6: bytebase.store.PlanCheckRunResult.Result.SqlReviewReport
}
var file_store_plan_check_run_proto_depIdxs = []int32{
- 3, // 0: bytebase.store.PlanCheckRunResult.results:type_name -> bytebase.store.PlanCheckRunResult.Result
- 0, // 1: bytebase.store.PlanCheckRunResult.Result.status:type_name -> bytebase.store.PlanCheckRunResult.Result.Status
- 4, // 2: bytebase.store.PlanCheckRunResult.Result.sql_summary_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport
- 5, // 3: bytebase.store.PlanCheckRunResult.Result.sql_review_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlReviewReport
- 4, // [4:4] is the sub-list for method output_type
- 4, // [4:4] is the sub-list for method input_type
- 4, // [4:4] is the sub-list for extension type_name
- 4, // [4:4] is the sub-list for extension extendee
- 0, // [0:4] is the sub-list for field type_name
+ 0, // 0: bytebase.store.PlanCheckRunConfig.change_database_type:type_name -> bytebase.store.PlanCheckRunConfig.ChangeDatabaseType
+ 4, // 1: bytebase.store.PlanCheckRunResult.results:type_name -> bytebase.store.PlanCheckRunResult.Result
+ 1, // 2: bytebase.store.PlanCheckRunResult.Result.status:type_name -> bytebase.store.PlanCheckRunResult.Result.Status
+ 5, // 3: bytebase.store.PlanCheckRunResult.Result.sql_summary_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport
+ 6, // 4: bytebase.store.PlanCheckRunResult.Result.sql_review_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlReviewReport
+ 5, // [5:5] is the sub-list for method output_type
+ 5, // [5:5] is the sub-list for method input_type
+ 5, // [5:5] is the sub-list for extension type_name
+ 5, // [5:5] is the sub-list for extension extendee
+ 0, // [0:5] is the sub-list for field type_name
}
func init() { file_store_plan_check_run_proto_init() }
@@ -585,7 +660,7 @@ func file_store_plan_check_run_proto_init() {
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_store_plan_check_run_proto_rawDesc,
- NumEnums: 1,
+ NumEnums: 2,
NumMessages: 5,
NumExtensions: 0,
NumServices: 0,
diff --git a/proto/store/plan_check_run.proto b/proto/store/plan_check_run.proto
index d198f454f8..78b5fdee7b 100644
--- a/proto/store/plan_check_run.proto
+++ b/proto/store/plan_check_run.proto
@@ -7,6 +7,14 @@ option go_package = "generated-go/store";
message PlanCheckRunConfig {
int32 sheet_id = 1;
int32 database_id = 2;
+ ChangeDatabaseType change_database_type = 3;
+
+ enum ChangeDatabaseType {
+ CHANGE_DATABASE_TYPE_UNSPECIFIED = 0;
+ DDL = 1;
+ DML = 2;
+ SDL = 3;
+ }
}
message PlanCheckRunResult {