Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: impl plan check statement report (#7628)
p0ny861478394c7e
diff --git a/backend/api/v1/rollout_service_plan_check.go b/backend/api/v1/rollout_service_plan_check.goindex c5cfe76873..91ce5b22f3 100644--- a/backend/api/v1/rollout_service_plan_check.go+++ b/backend/api/v1/rollout_service_plan_check.go@@ -111,6 +111,21 @@ func getPlanCheckRunsForSpec(ctx context.Context, s *store.Store, plan *store.Pl},})}+ if isStatementReportSupported(instance.Engine) {+ planCheckRuns = append(planCheckRuns, &store.PlanCheckRunMessage{+ CreatorUID: api.SystemBotID,+ UpdaterUID: api.SystemBotID,+ PlanUID: plan.UID,+ Status: store.PlanCheckRunStatusRunning,+ Type: store.PlanCheckDatabaseStatementSummaryReport,+ Config: &storepb.PlanCheckRunConfig{+ SheetId: int32(sheetUID),+ InstanceId: int32(instance.UID),+ DatabaseId: int32(database.UID),+ ChangeDatabaseType: convertToChangeDatabaseType(config.ChangeDatabaseConfig.Type),+ },+ })+ }if config.ChangeDatabaseConfig.Type == storepb.PlanConfig_ChangeDatabaseConfig_MIGRATE_GHOST {planCheckRuns = append(planCheckRuns, &store.PlanCheckRunMessage{CreatorUID: api.SystemBotID,@@ -236,3 +251,12 @@ func isStatementAdviseSupported(dbType db.Type) bool {return false}}++func isStatementReportSupported(dbType db.Type) bool {+ switch dbType {+ case db.Postgres, db.MySQL, db.OceanBase, db.Oracle:+ return true+ default:+ return false+ }+}diff --git a/backend/runner/plancheck/statement_report_executor.go b/backend/runner/plancheck/statement_report_executor.gonew file mode 100644index 0000000000..88759cbf3f--- /dev/null+++ b/backend/runner/plancheck/statement_report_executor.go@@ -0,0 +1,788 @@+package plancheck++import (+ "context"+ "database/sql"+ "fmt"+ "strings"++ pgquery "github.com/pganalyze/pg_query_go/v4"+ tidbparser "github.com/pingcap/tidb/parser"+ tidbast "github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors"+ "go.uber.org/zap"++ "github.com/bytebase/bytebase/backend/common"+ "github.com/bytebase/bytebase/backend/common/log"+ "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/store"+ "github.com/bytebase/bytebase/backend/utils"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"+)++// NewStatementReportExecutor creates a statement report executor.+func NewStatementReportExecutor(store *store.Store, dbFactory *dbfactory.DBFactory) Executor {+ return &StatementReportExecutor{+ store: store,+ dbFactory: dbFactory,+ }+}++// StatementReportExecutor is the statement report executor.+type StatementReportExecutor struct {+ store *store.Store+ dbFactory *dbfactory.DBFactory+}++// Run runs the statement report executor.+func (e *StatementReportExecutor) 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, 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)+ }+ charset := dbSchema.Metadata.CharacterSet+ collation := dbSchema.Metadata.Collation++ 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: "Report for large SQL is not supported",+ 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 := utils.GetSecretMapFromDatabaseMessage(database)+ // To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.+ renderedStatement := utils.RenderStatement(statement, materials)++ switch instance.Engine {+ case db.Postgres:+ driver, err := e.dbFactory.GetAdminDatabaseDriver(ctx, instance, database)+ if err != nil {+ return nil, err+ }+ defer driver.Close(ctx)+ sqlDB := driver.GetDB()++ return reportForPostgres(ctx, sqlDB, database.DatabaseName, renderedStatement)+ case db.MySQL, db.OceanBase:+ driver, err := e.dbFactory.GetAdminDatabaseDriver(ctx, instance, database)+ if err != nil {+ return nil, err+ }+ defer driver.Close(ctx)+ sqlDB := driver.GetDB()++ return reportForMySQL(ctx, sqlDB, instance.Engine, database.DatabaseName, renderedStatement, charset, collation)+ case db.Oracle:+ schema := ""+ if instance.Options == nil || !instance.Options.SchemaTenantMode {+ adminSource := utils.DataSourceFromInstanceWithType(instance, api.Admin)+ schema = adminSource.Username+ } else {+ schema = database.DatabaseName+ }+ return reportForOracle(database.DatabaseName, schema, renderedStatement)+ default:+ return []*storepb.PlanCheckRunResult_Result{+ {+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,+ Code: common.Ok.Int64(),+ Title: "Not available",+ Content: fmt.Sprintf("Report is not supported for %s", instance.Engine),+ },+ }, nil+ }+}++func reportForOracle(databaseName string, schemaName string, statement string) ([]*storepb.PlanCheckRunResult_Result, error) {+ singleSQLs, err := parser.SplitMultiSQL(parser.Oracle, 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_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ Code: advisor.StatementSyntaxError.Int64(),+ },+ },+ },+ }, nil+ }++ var results []*storepb.PlanCheckRunResult_Result++ for _, stmt := range singleSQLs {+ if stmt.Empty || stmt.Text == "" {+ continue+ }++ changedResources, err := getChangedResourcesForOracle(databaseName, schemaName, stmt.Text)+ if err != nil {+ log.Error("failed to extract changed resources", zap.String("statement", stmt.Text), zap.Error(err))+ }+ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,+ Code: common.Ok.Int64(),+ Title: "OK",+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ // TODO: support report statement type and affected rows for oracle+ StatementType: "UNKNOWN",+ AffectedRows: 0,+ ChangedResources: changedResources,+ },+ },+ })+ }+ return results, nil+}++func getChangedResourcesForOracle(databaseName string, schemaName string, statement string) (*storepb.ChangedResources, error) {+ resources, err := parser.ExtractChangedResources(parser.Oracle, databaseName, schemaName, statement)+ if err != nil {+ return nil, err+ }+ return convertToChangedResources(resources), nil+}++func reportForMySQL(ctx context.Context, sqlDB *sql.DB, dbType db.Type, databaseName, statement, charset, collation string) ([]*storepb.PlanCheckRunResult_Result, error) {+ singleSQLs, err := parser.SplitMultiSQL(parser.MySQL, 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_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ Code: advisor.StatementSyntaxError.Int64(),+ },+ },+ },+ }, nil+ }++ var results []*storepb.PlanCheckRunResult_Result++ p := tidbparser.New()+ p.EnableWindowFunc(true)++ for _, stmt := range singleSQLs {+ if stmt.Empty {+ continue+ }+ if parser.IsTiDBUnsupportDDLStmt(stmt.Text) {+ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,+ Title: "OK",+ Content: "",+ Code: common.Ok.Int64(),+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ StatementType: "UNKNOWN",+ AffectedRows: 0,+ },+ },+ })+ continue+ }+ root, _, err := p.Parse(stmt.Text, charset, collation)+ if err != nil {+ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_ERROR,+ Title: "Syntax error",+ Content: err.Error(),+ Code: 0,+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ Code: advisor.StatementSyntaxError.Int64(),+ },+ },+ })+ continue+ }+ if len(root) != 1 {+ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_ERROR,+ Title: "Failed to report statement type",+ Content: "Expect to get one node from parser",+ Code: common.Internal.Int64(),+ })+ continue+ }+ sqlType, resources := getStatementTypeFromTidbAstNode(strings.ToLower(databaseName), root[0])+ var changedResources *storepb.ChangedResources+ if !isDML(sqlType) {+ if dbType != db.TiDB {+ changedResources, err = getStatementChangedResourcesForMySQL(databaseName, stmt.Text)+ if err != nil {+ log.Error("failed to get statement changed resources", zap.Error(err))+ }+ } else {+ changedResources = convertToChangedResources(resources)+ }+ }++ affectedRows, err := getAffectedRowsForMysql(ctx, dbType, sqlDB, root[0])+ if err != nil {+ log.Error("failed to get affected rows for mysql", zap.String("database", databaseName), zap.Error(err))+ affectedRows = 0+ }++ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,+ Code: common.Ok.Int64(),+ Title: "OK",+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ StatementType: sqlType,+ AffectedRows: affectedRows,+ ChangedResources: changedResources,+ },+ },+ })+ }++ return results, nil+}++func isDML(tp string) bool {+ switch tp {+ case "REPLACE", "INSERT", "UPDATE", "DELETE":+ return true+ default:+ return false+ }+}++func convertToChangedResources(resources []parser.SchemaResource) *storepb.ChangedResources {+ meta := &storepb.ChangedResources{}+ // resources is ordered by (db, schema, table)+ for _, resource := range resources {+ if len(meta.Databases) == 0 || meta.Databases[len(meta.Databases)-1].Name != resource.Database {+ meta.Databases = append(meta.Databases, &storepb.ChangedResourceDatabase{Name: resource.Database})+ }+ database := meta.Databases[len(meta.Databases)-1]+ if len(database.Schemas) == 0 || database.Schemas[len(database.Schemas)-1].Name != resource.Schema {+ database.Schemas = append(database.Schemas, &storepb.ChangedResourceSchema{Name: resource.Schema})+ }+ schema := database.Schemas[len(database.Schemas)-1]+ schema.Tables = append(schema.Tables, &storepb.ChangedResourceTable{Name: resource.Table})+ }+ return meta+}++func getStatementChangedResourcesForMySQL(currentDatabase, statement string) (*storepb.ChangedResources, error) {+ resources, err := parser.ExtractChangedResources(parser.MySQL, currentDatabase, "" /* currentSchema */, statement)+ if err != nil {+ return nil, err+ }+ return convertToChangedResources(resources), nil+}++func reportForPostgres(ctx context.Context, sqlDB *sql.DB, database, statement string) ([]*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,+ Title: "Syntax error",+ Content: err.Error(),+ Code: 0,+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ Code: advisor.StatementSyntaxError.Int64(),+ },+ },+ },+ }, nil+ }++ var results []*storepb.PlanCheckRunResult_Result+ for _, stmt := range stmts {+ sqlType, resources := getStatementTypeAndResourcesFromAstNode(database, "public", stmt)+ if sqlType == "COMMENT" {+ resources, err = postgresExtractResourcesFromCommentStatement(database, "public", stmt.Text())+ if err != nil {+ log.Error("failed to extract resources from comment statement", zap.String("statement", stmt.Text()), zap.Error(err))+ resources = nil+ }+ }+ changedResource := convertToChangedResources(resources)++ rowCount, err := getAffectedRowsForPostgres(ctx, sqlDB, stmt)+ if err != nil {+ log.Error("failed to get affected rows for postgres", zap.String("database", database), zap.Error(err))+ rowCount = 0+ }++ results = append(results, &storepb.PlanCheckRunResult_Result{+ Status: storepb.PlanCheckRunResult_Result_SUCCESS,+ Code: common.Ok.Int64(),+ Title: "OK",+ Report: &storepb.PlanCheckRunResult_Result_SqlSummaryReport_{+ SqlSummaryReport: &storepb.PlanCheckRunResult_Result_SqlSummaryReport{+ StatementType: sqlType,+ AffectedRows: rowCount,+ ChangedResources: changedResource,+ },+ },+ })+ }++ return results, nil+}++func postgresExtractResourcesFromCommentStatement(database, defaultSchema, statement string) ([]parser.SchemaResource, error) {+ res, err := pgquery.Parse(statement)+ if err != nil {+ return nil, err+ }+ if len(res.Stmts) != 1 {+ return nil, errors.New("expect to get one node from parser")+ }+ for _, stmt := range res.Stmts {+ if comment, ok := stmt.Stmt.Node.(*pgquery.Node_CommentStmt); ok {+ switch comment.CommentStmt.Objtype {+ case pgquery.ObjectType_OBJECT_COLUMN:+ switch node := comment.CommentStmt.Object.Node.(type) {+ case *pgquery.Node_List:+ schemaName, tableName, _, err := convertColumnName(node)+ if err != nil {+ return nil, err+ }+ resource := parser.SchemaResource{+ Database: database,+ Schema: schemaName,+ Table: tableName,+ }+ if resource.Schema == "" {+ resource.Schema = defaultSchema+ }+ return []parser.SchemaResource{resource}, nil+ default:+ return nil, errors.Errorf("expect to get a list node but got %T", node)+ }+ case pgquery.ObjectType_OBJECT_TABCONSTRAINT:+ resource := parser.SchemaResource{+ Database: database,+ Schema: defaultSchema,+ }+ switch node := comment.CommentStmt.Object.Node.(type) {+ case *pgquery.Node_List:+ schemaName, tableName, _, err := convertConstraintName(node)+ if err != nil {+ return nil, err+ }+ if schemaName != "" {+ resource.Schema = schemaName+ }+ resource.Table = tableName+ return []parser.SchemaResource{resource}, nil+ default:+ return nil, errors.Errorf("expect to get a list node but got %T", node)+ }+ case pgquery.ObjectType_OBJECT_TABLE:+ resource := parser.SchemaResource{+ Database: database,+ Schema: defaultSchema,+ }+ switch node := comment.CommentStmt.Object.Node.(type) {+ case *pgquery.Node_List:+ schemaName, tableName, err := convertTableName(node)+ if err != nil {+ return nil, err+ }+ if schemaName != "" {+ resource.Schema = schemaName+ }+ resource.Table = tableName+ return []parser.SchemaResource{resource}, nil+ default:+ return nil, errors.Errorf("expect to get a list node but got %T", node)+ }+ }+ }+ }+ return nil, nil+}++func convertNodeList(node *pgquery.Node_List) ([]string, error) {+ var list []string+ for _, item := range node.List.Items {+ switch s := item.Node.(type) {+ case *pgquery.Node_String_:+ list = append(list, s.String_.Sval)+ default:+ return nil, errors.Errorf("expect to get a string node but got %T", s)+ }+ }+ return list, nil+}++func convertTableName(node *pgquery.Node_List) (string, string, error) {+ list, err := convertNodeList(node)+ if err != nil {+ return "", "", err+ }+ switch len(list) {+ case 2:+ return list[0], list[1], nil+ case 1:+ return "", list[0], nil+ default:+ return "", "", errors.Errorf("expect to get 1 or 2 items but got %d", len(list))+ }+}++func convertConstraintName(node *pgquery.Node_List) (string, string, string, error) {+ list, err := convertNodeList(node)+ if err != nil {+ return "", "", "", err+ }+ switch len(list) {+ case 3:+ return list[0], list[1], list[2], nil+ case 2:+ return "", list[0], list[1], nil+ default:+ return "", "", "", errors.Errorf("expect to get 2 or 3 items but got %d", len(list))+ }+}++func convertColumnName(node *pgquery.Node_List) (string, string, string, error) {+ list, err := convertNodeList(node)+ if err != nil {+ return "", "", "", err+ }+ switch len(list) {+ case 3:+ return list[0], list[1], list[2], nil+ case 2:+ return "", list[0], list[1], nil+ default:+ return "", "", "", errors.Errorf("expect to get 2 or 3 items but got %d", len(list))+ }+}++func getStatementTypeFromTidbAstNode(database string, node tidbast.StmtNode) (string, []parser.SchemaResource) {+ var result []parser.SchemaResource+ switch n := node.(type) {+ // DDL++ // CREATE+ case *tidbast.CreateDatabaseStmt:+ return "CREATE_DATABASE", result+ case *tidbast.CreateIndexStmt:+ return "CREATE_INDEX", result+ case *tidbast.CreateTableStmt:+ resource := parser.SchemaResource{+ Database: n.Table.Schema.L,+ Table: n.Table.Name.L,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ result = append(result, resource)+ return "CREATE_TABLE", result+ case *tidbast.CreateViewStmt:+ return "CREATE_VIEW", result+ case *tidbast.CreateSequenceStmt:+ return "CREATE_SEQUENCE", result+ case *tidbast.CreatePlacementPolicyStmt:+ return "CREATE_PLACEMENT_POLICY", result++ // DROP+ case *tidbast.DropIndexStmt:+ return "DROP_INDEX", result+ case *tidbast.DropTableStmt:+ for _, table := range n.Tables {+ resource := parser.SchemaResource{+ Database: table.Schema.L,+ Table: table.Name.L,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ result = append(result, resource)+ }+ return "DROP_TABLE", result+ case *tidbast.DropSequenceStmt:+ return "DROP_SEQUENCE", result+ case *tidbast.DropPlacementPolicyStmt:+ return "DROP_PLACEMENT_POLICY", result+ case *tidbast.DropDatabaseStmt:+ return "DROP_DATABASE", result++ // ALTER+ case *tidbast.AlterTableStmt:+ resource := parser.SchemaResource{+ Database: n.Table.Schema.L,+ Table: n.Table.Name.L,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ result = append(result, resource)+ return "ALTER_TABLE", result+ case *tidbast.AlterSequenceStmt:+ return "ALTER_SEQUENCE", result+ case *tidbast.AlterPlacementPolicyStmt:+ return "ALTER_PLACEMENT_POLICY", result++ // TRUNCATE+ case *tidbast.TruncateTableStmt:+ return "TRUNCATE", result++ // RENAME+ case *tidbast.RenameTableStmt:+ for _, pair := range n.TableToTables {+ resource := parser.SchemaResource{+ Database: pair.OldTable.Schema.L,+ Table: pair.OldTable.Name.L,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ result = append(result, resource)++ newResource := parser.SchemaResource{+ Database: pair.NewTable.Schema.L,+ Table: pair.NewTable.Name.L,+ }+ if newResource.Database == "" {+ newResource.Database = resource.Database+ }+ result = append(result, newResource)+ }+ return "RENAME_TABLE", result++ // DML++ case *tidbast.InsertStmt:+ if n.IsReplace {+ return "REPLACE", result+ }+ return "INSERT", result+ case *tidbast.DeleteStmt:+ return "DELETE", result+ case *tidbast.UpdateStmt:+ return "UPDATE", result+ }+ return "UNKNOWN", result+}++func getStatementTypeAndResourcesFromAstNode(database, schema string, node ast.Node) (string, []parser.SchemaResource) {+ result := []parser.SchemaResource{}+ switch node := node.(type) {+ // DDL++ // CREATE+ case *ast.CreateIndexStmt:+ return "CREATE_INDEX", result+ case *ast.CreateTableStmt:+ switch node.Name.Type {+ case ast.TableTypeView:+ return "CREATE_VIEW", result+ case ast.TableTypeBaseTable:+ resource := parser.SchemaResource{+ Database: node.Name.Database,+ Schema: node.Name.Schema,+ Table: node.Name.Name,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ if resource.Schema == "" {+ resource.Schema = schema+ }+ result = append(result, resource)+ return "CREATE_TABLE", result+ }+ case *ast.CreateSequenceStmt:+ return "CREATE_SEQUENCE", result+ case *ast.CreateDatabaseStmt:+ return "CREATE_DATABASE", result+ case *ast.CreateSchemaStmt:+ return "CREATE_SCHEMA", result+ case *ast.CreateFunctionStmt:+ return "CREATE_FUNCTION", result+ case *ast.CreateTriggerStmt:+ return "CREATE_TRIGGER", result+ case *ast.CreateTypeStmt:+ return "CREATE_TYPE", result+ case *ast.CreateExtensionStmt:+ return "CREATE_EXTENSION", result++ // DROP+ case *ast.DropColumnStmt:+ return "DROP_COLUMN", result+ case *ast.DropConstraintStmt:+ return "DROP_CONSTRAINT", result+ case *ast.DropDatabaseStmt:+ return "DROP_DATABASE", result+ case *ast.DropDefaultStmt:+ return "DROP_DEFAULT", result+ case *ast.DropExtensionStmt:+ return "DROP_EXTENSION", result+ case *ast.DropFunctionStmt:+ return "DROP_FUNCTION", result+ case *ast.DropIndexStmt:+ return "DROP_INDEX", result+ case *ast.DropNotNullStmt:+ return "DROP_NOT_NULL", result+ case *ast.DropSchemaStmt:+ return "DROP_SCHEMA", result+ case *ast.DropSequenceStmt:+ return "DROP_SEQUENCE", result+ case *ast.DropTableStmt:+ for _, table := range node.TableList {+ resource := parser.SchemaResource{+ Database: table.Database,+ Schema: table.Schema,+ Table: table.Name,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ if resource.Schema == "" {+ resource.Schema = schema+ }+ result = append(result, resource)+ }+ return "DROP_TABLE", result++ case *ast.DropTriggerStmt:+ return "DROP_TRIGGER", result+ case *ast.DropTypeStmt:+ return "DROP_TYPE", result++ // ALTER+ case *ast.AlterColumnTypeStmt:+ return "ALTER_COLUMN_TYPE", result+ case *ast.AlterSequenceStmt:+ return "ALTER_SEQUENCE", result+ case *ast.AlterTableStmt:+ switch node.Table.Type {+ case ast.TableTypeView:+ return "ALTER_VIEW", result+ case ast.TableTypeBaseTable:+ resource := parser.SchemaResource{+ Database: node.Table.Database,+ Schema: node.Table.Schema,+ Table: node.Table.Name,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ if resource.Schema == "" {+ resource.Schema = schema+ }+ result = append(result, resource)+ return "ALTER_TABLE", result+ }+ case *ast.AlterTypeStmt:+ return "ALTER_TYPE", result++ case *ast.AddColumnListStmt:+ return "ALTER_TABLE_ADD_COLUMN_LIST", result+ case *ast.AddConstraintStmt:+ return "ALTER_TABLE_ADD_CONSTRAINT", result++ // RENAME+ case *ast.RenameColumnStmt:+ return "RENAME_COLUMN", result+ case *ast.RenameConstraintStmt:+ return "RENAME_CONSTRAINT", result+ case *ast.RenameIndexStmt:+ return "RENAME_INDEX", result+ case *ast.RenameSchemaStmt:+ return "RENAME_SCHEMA", result+ case *ast.RenameTableStmt:+ switch node.Table.Type {+ case ast.TableTypeView:+ return "RENAME_VIEW", result+ case ast.TableTypeBaseTable:+ resource := parser.SchemaResource{+ Database: node.Table.Database,+ Schema: node.Table.Schema,+ Table: node.Table.Name,+ }+ if resource.Database == "" {+ resource.Database = database+ }+ if resource.Schema == "" {+ resource.Schema = schema+ }+ result = append(result, resource)++ newResource := parser.SchemaResource{+ Database: resource.Database,+ Schema: resource.Schema,+ Table: node.NewName,+ }+ result = append(result, newResource)+ return "RENAME_TABLE", result+ }++ case *ast.CommentStmt:+ return "COMMENT", result++ // DML++ case *ast.InsertStmt:+ return "INSERT", result+ case *ast.UpdateStmt:+ return "UPDATE", result+ case *ast.DeleteStmt:+ return "DELETE", result+ }++ return "UNKNOWN", result+}diff --git a/backend/runner/plancheck/statement_report_executor_affected_rows.go b/backend/runner/plancheck/statement_report_executor_affected_rows.gonew file mode 100644index 0000000000..56e6372cd0--- /dev/null+++ b/backend/runner/plancheck/statement_report_executor_affected_rows.go@@ -0,0 +1,330 @@+package plancheck++import (+ "context"+ "database/sql"+ "encoding/json"+ "fmt"+ "regexp"+ "strconv"+ "strings"++ tidbast "github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors"++ "github.com/bytebase/bytebase/backend/plugin/db"+ "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"+)++func getAffectedRowsForPostgres(ctx context.Context, sqlDB *sql.DB, node ast.Node) (int64, error) {+ switch node := node.(type) {+ case *ast.InsertStmt, *ast.UpdateStmt, *ast.DeleteStmt:+ if node, ok := node.(*ast.InsertStmt); ok && len(node.ValueList) > 0 {+ return int64(len(node.ValueList)), nil+ }+ return getAffectedRowsCount(ctx, sqlDB, fmt.Sprintf("EXPLAIN %s", node.Text()), getAffectedRowsCountForPostgres)+ default:+ return 0, nil+ }+}++func getAffectedRowsCountForPostgres(res []any) (int64, error) {+ // the res struct is []any{columnName, columnTable, rowDataList}+ if len(res) != 3 {+ return 0, errors.Errorf("expected 3 but got %d", len(res))+ }+ rowList, ok := res[2].([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", res[2])+ }+ // test-bb=# EXPLAIN INSERT INTO t SELECT * FROM t;+ // QUERY PLAN+ // -------------------------------------------------------------+ // Insert on t (cost=0.00..1.03 rows=0 width=0)+ // -> Seq Scan on t t_1 (cost=0.00..1.03 rows=3 width=520)+ // (2 rows)+ if len(rowList) < 2 {+ return 0, errors.Errorf("not found any data")+ }+ // We need the row 2.+ rowTwo, ok := rowList[1].([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", rowList[0])+ }+ // PostgreSQL EXPLAIN statement result has one column.+ if len(rowTwo) != 1 {+ return 0, errors.Errorf("expected one but got %d", len(rowTwo))+ }+ // Get the string value.+ text, ok := rowTwo[0].(string)+ if !ok {+ return 0, errors.Errorf("expected string but got %t", rowTwo[0])+ }++ rowsRegexp := regexp.MustCompile("rows=([0-9]+)")+ matches := rowsRegexp.FindStringSubmatch(text)+ if len(matches) != 2 {+ return 0, errors.Errorf("failed to find rows in %q", text)+ }+ value, err := strconv.ParseInt(matches[1], 10, 64)+ if err != nil {+ return 0, errors.Errorf("failed to get integer from %q", matches[1])+ }+ return value, nil+}++type affectedRowsCountExtractor func(res []any) (int64, error)++func getAffectedRowsCount(ctx context.Context, sqlDB *sql.DB, explainSQL string, extractor affectedRowsCountExtractor) (int64, error) {+ res, err := query(ctx, sqlDB, explainSQL)+ if err != nil {+ return 0, err+ }+ rowCount, err := extractor(res)+ if err != nil {+ return 0, errors.Wrapf(err, "failed to get affected rows count, res %+v", res)+ }+ return rowCount, nil+}++// Query runs the EXPLAIN or SELECT statements for advisors.+func query(ctx context.Context, connection *sql.DB, statement string) ([]any, error) {+ tx, err := connection.BeginTx(ctx, &sql.TxOptions{})+ if err != nil {+ return nil, err+ }+ defer tx.Rollback()++ rows, err := tx.QueryContext(ctx, statement)+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ columnNames, err := rows.Columns()+ if err != nil {+ return nil, err+ }++ columnTypes, err := rows.ColumnTypes()+ if err != nil {+ return nil, err+ }++ colCount := len(columnTypes)++ var columnTypeNames []string+ for _, v := range columnTypes {+ // DatabaseTypeName returns the database system name of the column type.+ // refer: https://pkg.go.dev/database/sql#ColumnType.DatabaseTypeName+ columnTypeNames = append(columnTypeNames, strings.ToUpper(v.DatabaseTypeName()))+ }++ data := []any{}+ for rows.Next() {+ scanArgs := make([]any, colCount)+ for i, v := range columnTypeNames {+ // TODO(steven need help): Consult a common list of data types from database driver documentation. e.g. MySQL,PostgreSQL.+ switch v {+ case "VARCHAR", "TEXT", "UUID", "TIMESTAMP":+ scanArgs[i] = new(sql.NullString)+ case "BOOL":+ scanArgs[i] = new(sql.NullBool)+ case "INT", "INTEGER":+ scanArgs[i] = new(sql.NullInt64)+ case "FLOAT":+ scanArgs[i] = new(sql.NullFloat64)+ default:+ scanArgs[i] = new(sql.NullString)+ }+ }++ if err := rows.Scan(scanArgs...); err != nil {+ return nil, err+ }++ rowData := []any{}+ for i := range columnTypes {+ if v, ok := (scanArgs[i]).(*sql.NullBool); ok && v.Valid {+ rowData = append(rowData, v.Bool)+ continue+ }+ if v, ok := (scanArgs[i]).(*sql.NullString); ok && v.Valid {+ rowData = append(rowData, v.String)+ continue+ }+ if v, ok := (scanArgs[i]).(*sql.NullInt64); ok && v.Valid {+ rowData = append(rowData, v.Int64)+ continue+ }+ if v, ok := (scanArgs[i]).(*sql.NullInt32); ok && v.Valid {+ rowData = append(rowData, v.Int32)+ continue+ }+ if v, ok := (scanArgs[i]).(*sql.NullFloat64); ok && v.Valid {+ rowData = append(rowData, v.Float64)+ continue+ }+ // If none of them match, set nil to its value.+ rowData = append(rowData, nil)+ }++ data = append(data, rowData)+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }++ return []any{columnNames, columnTypeNames, data}, nil+}++func getAffectedRowsForMysql(ctx context.Context, dbType db.Type, sqlDB *sql.DB, node tidbast.StmtNode) (int64, error) {+ switch node := node.(type) {+ case *tidbast.InsertStmt, *tidbast.UpdateStmt, *tidbast.DeleteStmt:+ if node, ok := node.(*tidbast.InsertStmt); ok && node.Select == nil {+ return int64(len(node.Lists)), nil+ }+ if dbType == db.OceanBase {+ return getAffectedRowsCount(ctx, sqlDB, fmt.Sprintf("EXPLAIN FORMAT=JSON %s", node.Text()), getAffectedRowsCountForOceanBase)+ }+ return getAffectedRowsCount(ctx, sqlDB, fmt.Sprintf("EXPLAIN %s", node.Text()), getAffectedRowsCountForMysql)+ default:+ return 0, nil+ }+}++// OceanBaseQueryPlan represents the query plan of OceanBase.+type OceanBaseQueryPlan struct {+ ID int `json:"ID"`+ Operator string `json:"OPERATOR"`+ Name string `json:"NAME"`+ EstRows int64 `json:"EST.ROWS"`+ Cost int `json:"COST"`+ OutPut any `json:"output"`+}++// Unmarshal parses data and stores the result to current OceanBaseQueryPlan.+func (plan *OceanBaseQueryPlan) Unmarshal(data any) error {+ b, err := json.Marshal(data)+ if err != nil {+ return err+ }+ if b != nil {+ return json.Unmarshal(b, &plan)+ }+ return nil+}++func getAffectedRowsCountForOceanBase(res []any) (int64, error) {+ // the res struct is []any{columnName, columnTable, rowDataList}+ if len(res) != 3 {+ return 0, errors.Errorf("expected 3 but got %d", len(res))+ }+ rowList, ok := res[2].([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", res[2])+ }+ if len(rowList) < 1 {+ return 0, errors.Errorf("not found any data")+ }++ plan, ok := rowList[0].([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", rowList[0])+ }+ planString, ok := plan[0].(string)+ if !ok {+ return 0, errors.Errorf("expected string but got %t", plan[0])+ }+ var planValue map[string]json.RawMessage+ if err := json.Unmarshal([]byte(planString), &planValue); err != nil {+ return 0, errors.Wrapf(err, "failed to parse query plan from string: %+v", planString)+ }+ if len(planValue) > 0 {+ queryPlan := OceanBaseQueryPlan{}+ if err := queryPlan.Unmarshal(planValue); err != nil {+ return 0, errors.Wrapf(err, "failed to parse query plan from map: %+v", planValue)+ }+ if queryPlan.Operator != "" {+ return queryPlan.EstRows, nil+ }+ count := int64(-1)+ for k, v := range planValue {+ if !strings.HasPrefix(k, "CHILD_") {+ continue+ }+ child := OceanBaseQueryPlan{}+ if err := child.Unmarshal(v); err != nil {+ return 0, errors.Wrapf(err, "failed to parse field '%s', value: %+v", k, v)+ }+ if child.Operator != "" && child.EstRows > count {+ count = child.EstRows+ }+ }+ if count >= 0 {+ return count, nil+ }+ }+ return 0, errors.Errorf("failed to extract 'EST.ROWS' from query plan")+}++func getAffectedRowsCountForMysql(res []any) (int64, error) {+ // the res struct is []any{columnName, columnTable, rowDataList}+ if len(res) != 3 {+ return 0, errors.Errorf("expected 3 but got %d", len(res))+ }+ rowList, ok := res[2].([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", res[2])+ }+ if len(rowList) < 1 {+ return 0, errors.Errorf("not found any data")+ }++ // MySQL EXPLAIN statement result has 12 columns.+ // the column 9 is the data 'rows'.+ // the first not-NULL value of column 9 is the affected rows count.+ //+ // mysql> explain delete from td;+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------++ // | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------++ // | 1 | DELETE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | NULL |+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------++ //+ // mysql> explain insert into td select * from td;+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------++ // | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------++ // | 1 | INSERT | td | NULL | ALL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |+ // | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |+ // +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+++ for _, rowAny := range rowList {+ row, ok := rowAny.([]any)+ if !ok {+ return 0, errors.Errorf("expected []any but got %t", row)+ }+ if len(row) != 12 {+ return 0, errors.Errorf("expected 12 but got %d", len(row))+ }+ switch col := row[9].(type) {+ case int:+ return int64(col), nil+ case int32:+ return int64(col), nil+ case int64:+ return col, nil+ case string:+ v, err := strconv.ParseInt(col, 10, 64)+ if err != nil {+ return 0, errors.Errorf("expected int or int64 but got string(%s)", col)+ }+ return v, nil+ default:+ continue+ }+ }++ return 0, errors.Errorf("failed to extract rows from query plan")+}diff --git a/backend/server/server.go b/backend/server/server.goindex 1c2ed45cba..79a90a6151 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -518,6 +518,8 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s.PlanCheckScheduler.Register(store.PlanCheckDatabaseGhostSync, ghostSyncExecutor)pitrMySQLExecutor := plancheck.NewPITRMySQLExecutor(storeInstance, s.dbFactory)s.PlanCheckScheduler.Register(store.PlanCheckDatabasePITRMySQL, pitrMySQLExecutor)+ statementReportExecutor := plancheck.NewStatementReportExecutor(storeInstance, s.dbFactory)+ s.PlanCheckScheduler.Register(store.PlanCheckDatabaseStatementSummaryReport, statementReportExecutor)}// Anomaly scannerdiff --git a/frontend/src/types/proto/store/plan_check_run.ts b/frontend/src/types/proto/store/plan_check_run.tsindex 751acb2d90..dcf6667f73 100644--- a/frontend/src/types/proto/store/plan_check_run.ts+++ b/frontend/src/types/proto/store/plan_check_run.ts@@ -1,6 +1,7 @@/* eslint-disable */import * as Long from "long";import * as _m0 from "protobufjs/minimal";+import { ChangedResources } from "./instance_change_history";export const protobufPackage = "bytebase.store";@@ -122,8 +123,10 @@ export function planCheckRunResult_Result_StatusToJSON(object: PlanCheckRunResul}export interface PlanCheckRunResult_Result_SqlSummaryReport {+ code: number;statementType: string;affectedRows: number;+ changedResources?: ChangedResources | undefined;}export interface PlanCheckRunResult_Result_SqlReviewReport {@@ -534,16 +537,22 @@ export const PlanCheckRunResult_Result = {};function createBasePlanCheckRunResult_Result_SqlSummaryReport(): PlanCheckRunResult_Result_SqlSummaryReport {- return { statementType: "", affectedRows: 0 };+ return { code: 0, statementType: "", affectedRows: 0, changedResources: undefined };}export const PlanCheckRunResult_Result_SqlSummaryReport = {encode(message: PlanCheckRunResult_Result_SqlSummaryReport, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {+ if (message.code !== 0) {+ writer.uint32(8).int64(message.code);+ }if (message.statementType !== "") {- writer.uint32(10).string(message.statementType);+ writer.uint32(18).string(message.statementType);}if (message.affectedRows !== 0) {- writer.uint32(16).int64(message.affectedRows);+ writer.uint32(24).int64(message.affectedRows);+ }+ if (message.changedResources !== undefined) {+ ChangedResources.encode(message.changedResources, writer.uint32(34).fork()).ldelim();}return writer;},@@ -556,19 +565,33 @@ export const PlanCheckRunResult_Result_SqlSummaryReport = {const tag = reader.uint32();switch (tag >>> 3) {case 1:- if (tag !== 10) {+ if (tag !== 8) {break;}- message.statementType = reader.string();+ message.code = longToNumber(reader.int64() as Long);continue;case 2:- if (tag !== 16) {+ if (tag !== 18) {+ break;+ }++ message.statementType = reader.string();+ continue;+ case 3:+ if (tag !== 24) {break;}message.affectedRows = longToNumber(reader.int64() as Long);continue;+ case 4:+ if (tag !== 34) {+ break;+ }++ message.changedResources = ChangedResources.decode(reader, reader.uint32());+ continue;}if ((tag & 7) === 4 || tag === 0) {break;@@ -580,15 +603,20 @@ export const PlanCheckRunResult_Result_SqlSummaryReport = {fromJSON(object: any): PlanCheckRunResult_Result_SqlSummaryReport {return {+ code: isSet(object.code) ? Number(object.code) : 0,statementType: isSet(object.statementType) ? String(object.statementType) : "",affectedRows: isSet(object.affectedRows) ? Number(object.affectedRows) : 0,+ changedResources: isSet(object.changedResources) ? ChangedResources.fromJSON(object.changedResources) : undefined,};},toJSON(message: PlanCheckRunResult_Result_SqlSummaryReport): unknown {const obj: any = {};+ message.code !== undefined && (obj.code = Math.round(message.code));message.statementType !== undefined && (obj.statementType = message.statementType);message.affectedRows !== undefined && (obj.affectedRows = Math.round(message.affectedRows));+ message.changedResources !== undefined &&+ (obj.changedResources = message.changedResources ? ChangedResources.toJSON(message.changedResources) : undefined);return obj;},@@ -600,8 +628,12 @@ export const PlanCheckRunResult_Result_SqlSummaryReport = {object: DeepPartial<PlanCheckRunResult_Result_SqlSummaryReport>,): PlanCheckRunResult_Result_SqlSummaryReport {const message = createBasePlanCheckRunResult_Result_SqlSummaryReport();+ message.code = object.code ?? 0;message.statementType = object.statementType ?? "";message.affectedRows = object.affectedRows ?? 0;+ message.changedResources = (object.changedResources !== undefined && object.changedResources !== null)+ ? ChangedResources.fromPartial(object.changedResources)+ : undefined;return message;},};diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex f22ac339cd..890d406958 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -1741,8 +1741,10 @@ Type is the database change type.| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |+| code | [int64](#int64) | | || statement_type | [string](#string) | | || affected_rows | [int64](#int64) | | |+| changed_resources | [ChangedResources](#bytebase-store-ChangedResources) | | |diff --git a/proto/generated-go/store/plan_check_run.pb.go b/proto/generated-go/store/plan_check_run.pb.goindex 979e0f2242..59917f464e 100644--- a/proto/generated-go/store/plan_check_run.pb.go+++ b/proto/generated-go/store/plan_check_run.pb.go@@ -431,8 +431,10 @@ type PlanCheckRunResult_Result_SqlSummaryReport struct {sizeCache protoimpl.SizeCacheunknownFields protoimpl.UnknownFields- StatementType string `protobuf:"bytes,1,opt,name=statement_type,json=statementType,proto3" json:"statement_type,omitempty"`- AffectedRows int64 `protobuf:"varint,2,opt,name=affected_rows,json=affectedRows,proto3" json:"affected_rows,omitempty"`+ Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`+ StatementType string `protobuf:"bytes,2,opt,name=statement_type,json=statementType,proto3" json:"statement_type,omitempty"`+ AffectedRows int64 `protobuf:"varint,3,opt,name=affected_rows,json=affectedRows,proto3" json:"affected_rows,omitempty"`+ ChangedResources *ChangedResources `protobuf:"bytes,4,opt,name=changed_resources,json=changedResources,proto3" json:"changed_resources,omitempty"`}func (x *PlanCheckRunResult_Result_SqlSummaryReport) Reset() {@@ -467,6 +469,13 @@ func (*PlanCheckRunResult_Result_SqlSummaryReport) Descriptor() ([]byte, []int)return file_store_plan_check_run_proto_rawDescGZIP(), []int{1, 0, 0}}+func (x *PlanCheckRunResult_Result_SqlSummaryReport) GetCode() int64 {+ if x != nil {+ return x.Code+ }+ return 0+}+func (x *PlanCheckRunResult_Result_SqlSummaryReport) GetStatementType() string {if x != nil {return x.StatementType@@ -481,6 +490,13 @@ func (x *PlanCheckRunResult_Result_SqlSummaryReport) GetAffectedRows() int64 {return 0}+func (x *PlanCheckRunResult_Result_SqlSummaryReport) GetChangedResources() *ChangedResources {+ if x != nil {+ return x.ChangedResources+ }+ return nil+}+type PlanCheckRunResult_Result_SqlReviewReport struct {state protoimpl.MessageStatesizeCache protoimpl.SizeCache@@ -558,88 +574,97 @@ var File_store_plan_check_run_proto protoreflect.FileDescriptorvar 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, 0xef, 0x03, 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, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20,- 0x01, 0x28, 0x05, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x64, 0x12,- 0x1f, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03,- 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, 0x04, 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, 0x12, 0x4e, 0x0a, 0x0b, 0x70, 0x69, 0x74,- 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d,- 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, 0x50, 0x69, 0x74, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0a, 0x70,- 0x69, 0x74, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x6c, 0x0a, 0x0a, 0x50, 0x69, 0x74,- 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x2c, 0x0a, 0x12, 0x74, 0x61, 0x72, 0x67, 0x65,- 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,- 0x01, 0x28, 0x05, 0x52, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x49, 0x6e, 0x73, 0x74, 0x61,- 0x6e, 0x63, 0x65, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f,- 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20,- 0x01, 0x28, 0x09, 0x52, 0x12, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x62,- 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 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, 0xf9,- 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, 0x87, 0x05, 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, 0x1a, 0x23, 0x73, 0x74,+ 0x6f, 0x72, 0x65, 0x2f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x63, 0x68, 0x61,+ 0x6e, 0x67, 0x65, 0x5f, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74,+ 0x6f, 0x22, 0xef, 0x03, 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, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f,+ 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e,+ 0x63, 0x65, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,+ 0x5f, 0x69, 0x64, 0x18, 0x03, 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, 0x04, 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, 0x12, 0x4e,+ 0x0a, 0x0b, 0x70, 0x69, 0x74, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x05, 0x20,+ 0x01, 0x28, 0x0b, 0x32, 0x2d, 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, 0x50, 0x69, 0x74, 0x72, 0x43, 0x6f, 0x6e, 0x66,+ 0x69, 0x67, 0x52, 0x0a, 0x70, 0x69, 0x74, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x6c,+ 0x0a, 0x0a, 0x50, 0x69, 0x74, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x2c, 0x0a, 0x12,+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f,+ 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74,+ 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x74, 0x61,+ 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x6e, 0x61,+ 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74,+ 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 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, 0xdd, 0x06, 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, 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,+ 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, 0xeb, 0x05, 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, 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, 0x69,- 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, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x18,- 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x12, 0x16, 0x0a,- 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64,- 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 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,+ 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, 0xc1, 0x01, 0x0a, 0x10, 0x53, 0x71, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61,+ 0x72, 0x79, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65,+ 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x25, 0x0a, 0x0e,+ 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02,+ 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, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x61, 0x66, 0x66, 0x65,+ 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x77, 0x73, 0x12, 0x4d, 0x0a, 0x11, 0x63, 0x68, 0x61, 0x6e,+ 0x67, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x18, 0x04, 0x20,+ 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73,+ 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x52, 0x65, 0x73, 0x6f,+ 0x75, 0x72, 0x63, 0x65, 0x73, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x52, 0x65,+ 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x1a, 0x69, 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, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06,+ 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c,+ 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x12,+ 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 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 (@@ -665,6 +690,7 @@ var file_store_plan_check_run_proto_goTypes = []interface{}{(*PlanCheckRunResult_Result)(nil), // 5: bytebase.store.PlanCheckRunResult.Result(*PlanCheckRunResult_Result_SqlSummaryReport)(nil), // 6: bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport(*PlanCheckRunResult_Result_SqlReviewReport)(nil), // 7: bytebase.store.PlanCheckRunResult.Result.SqlReviewReport+ (*ChangedResources)(nil), // 8: bytebase.store.ChangedResources}var file_store_plan_check_run_proto_depIdxs = []int32{0, // 0: bytebase.store.PlanCheckRunConfig.change_database_type:type_name -> bytebase.store.PlanCheckRunConfig.ChangeDatabaseType@@ -673,11 +699,12 @@ var file_store_plan_check_run_proto_depIdxs = []int32{1, // 3: bytebase.store.PlanCheckRunResult.Result.status:type_name -> bytebase.store.PlanCheckRunResult.Result.Status6, // 4: bytebase.store.PlanCheckRunResult.Result.sql_summary_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport7, // 5: bytebase.store.PlanCheckRunResult.Result.sql_review_report:type_name -> bytebase.store.PlanCheckRunResult.Result.SqlReviewReport- 6, // [6:6] is the sub-list for method output_type- 6, // [6:6] is the sub-list for method input_type- 6, // [6:6] is the sub-list for extension type_name- 6, // [6:6] is the sub-list for extension extendee- 0, // [0:6] is the sub-list for field type_name+ 8, // 6: bytebase.store.PlanCheckRunResult.Result.SqlSummaryReport.changed_resources:type_name -> bytebase.store.ChangedResources+ 7, // [7:7] is the sub-list for method output_type+ 7, // [7:7] is the sub-list for method input_type+ 7, // [7:7] is the sub-list for extension type_name+ 7, // [7:7] is the sub-list for extension extendee+ 0, // [0:7] is the sub-list for field type_name}func init() { file_store_plan_check_run_proto_init() }@@ -685,6 +712,7 @@ func file_store_plan_check_run_proto_init() {if File_store_plan_check_run_proto != nil {return}+ file_store_instance_change_history_proto_init()if !protoimpl.UnsafeEnabled {file_store_plan_check_run_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {switch v := v.(*PlanCheckRunConfig); i {diff --git a/proto/store/plan_check_run.proto b/proto/store/plan_check_run.protoindex 3200b3a2fd..17263e2f74 100644--- a/proto/store/plan_check_run.proto+++ b/proto/store/plan_check_run.proto@@ -2,6 +2,8 @@ syntax = "proto3";package bytebase.store;+import "store/instance_change_history.proto";+option go_package = "generated-go/store";message PlanCheckRunConfig {@@ -45,8 +47,10 @@ message PlanCheckRunResult {SqlReviewReport sql_review_report = 6;}message SqlSummaryReport {- string statement_type = 1;- int64 affected_rows = 2;+ int64 code = 1;+ string statement_type = 2;+ int64 affected_rows = 3;+ ChangedResources changed_resources = 4;}message SqlReviewReport {int64 line = 1;