Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: migrate test to CI/CD v2 (part2) (#7795)
Danny Xu92a8d9e376b9
diff --git a/backend/tests/rollout.go b/backend/tests/rollout.goindex 452368d2db..213c825b42 100644--- a/backend/tests/rollout.go+++ b/backend/tests/rollout.go@@ -11,7 +11,7 @@ import (v1pb "github.com/bytebase/bytebase/proto/generated-go/v1")-func (ctl *controller) changeDatabase(ctx context.Context, project *v1pb.Project, database *v1pb.Database, sheet *v1pb.Sheet, changeType v1pb.Plan_ChangeDatabaseConfig_Type) (*v1pb.Plan, *v1pb.Rollout, error) {+func (ctl *controller) changeDatabase(ctx context.Context, project *v1pb.Project, database *v1pb.Database, sheet *v1pb.Sheet, changeType v1pb.Plan_ChangeDatabaseConfig_Type) error {plan, err := ctl.rolloutServiceClient.CreatePlan(ctx, &v1pb.CreatePlanRequest{Parent: project.Name,Plan: &v1pb.Plan{@@ -33,11 +33,11 @@ func (ctl *controller) changeDatabase(ctx context.Context, project *v1pb.Project},})if err != nil {- return nil, nil, errors.Wrapf(err, "failed to create plan")+ return errors.Wrapf(err, "failed to create plan")}rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})if err != nil {- return nil, nil, errors.Wrapf(err, "failed to create rollout")+ return errors.Wrapf(err, "failed to create rollout")}_, err = ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{Parent: project.Name,@@ -51,13 +51,13 @@ func (ctl *controller) changeDatabase(ctx context.Context, project *v1pb.Project},})if err != nil {- return nil, nil, errors.Wrapf(err, "failed to create issue")+ return errors.Wrapf(err, "failed to create issue")}err = ctl.waitRollout(ctx, rollout.Name)if err != nil {- return nil, nil, err+ return err}- return plan, rollout, nil+ return nil}// waitRollout waits for pipeline to finish and approves tasks when necessary.diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.goindex f0f0f5b5b8..428adb22b9 100644--- a/backend/tests/schema_update_test.go+++ b/backend/tests/schema_update_test.go@@ -123,7 +123,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {a.NoError(err)// Create an issue that updates database schema.- _, _, err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_MIGRATE)+ err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_MIGRATE)a.NoError(err)// Query schema.@@ -144,7 +144,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {a.NoError(err)// Create an issue that updates database data.- _, _, err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_DATA)+ err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_DATA)a.NoError(err)// Get migration history.diff --git a/backend/tests/sheet_vcs_test.go b/backend/tests/sheet_vcs_test.goindex e6df8c19fd..fcf33a5f46 100644--- a/backend/tests/sheet_vcs_test.go+++ b/backend/tests/sheet_vcs_test.go@@ -46,8 +46,9 @@ func TestSheetVCS(t *testing.T) {ctx := context.Background()ctl := &controller{}ctx, err := ctl.StartServerWithExternalPg(ctx, &config{- dataDir: t.TempDir(),- vcsProviderCreator: test.vcsProviderCreator,+ dataDir: t.TempDir(),+ vcsProviderCreator: test.vcsProviderCreator,+ developmentUseV2Scheduler: true,})a.NoError(err)defer func() {diff --git a/backend/tests/sql.go b/backend/tests/sql.goindex 477fe7441d..572c25bdb3 100644--- a/backend/tests/sql.go+++ b/backend/tests/sql.go@@ -9,7 +9,6 @@ import ("github.com/pkg/errors"- api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/plugin/advisor""github.com/bytebase/bytebase/backend/plugin/advisor/db"parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"@@ -38,65 +37,22 @@ func (ctl *controller) adminQuery(ctx context.Context, instance *v1pb.Instance,return resp.Results, nil}-// sqlReviewTaskCheckRunFinished will return SQL review task check result for next task.-// If the SQL review task check is not done, return nil, false, nil.-func (*controller) sqlReviewTaskCheckRunFinished(issue *api.Issue) ([]api.TaskCheckResult, bool, error) {- var result []api.TaskCheckResult- var latestTs int64- for _, stage := range issue.Pipeline.StageList {- for _, task := range stage.TaskList {- if task.Status == api.TaskPendingApproval {- for _, taskCheck := range task.TaskCheckRunList {- if taskCheck.Type == api.TaskCheckDatabaseStatementAdvise {- switch taskCheck.Status {- case api.TaskCheckRunRunning:- return nil, false, nil- case api.TaskCheckRunDone:- // return the latest result- if latestTs != 0 && latestTs > taskCheck.UpdatedTs {- continue- }- checkResult := &api.TaskCheckRunResultPayload{}- if err := json.Unmarshal([]byte(taskCheck.Result), checkResult); err != nil {- return nil, false, err- }- result = checkResult.ResultList- }- }- }- return result, true, nil- }- }- }- return nil, true, nil-}-// GetSQLReviewResult will wait for next task SQL review task check to finish and return the task check result.-func (ctl *controller) GetSQLReviewResult(id int) ([]api.TaskCheckResult, error) {+func (ctl *controller) GetSQLReviewResult(ctx context.Context, plan *v1pb.Plan) (*v1pb.PlanCheckRun, error) {ticker := time.NewTicker(100 * time.Millisecond)defer ticker.Stop()for range ticker.C {- issue, err := ctl.getIssue(id)+ resp, err := ctl.rolloutServiceClient.ListPlanCheckRuns(ctx, &v1pb.ListPlanCheckRunsRequest{+ Parent: plan.Name,+ })if err != nil {return nil, err}-- status, err := getNextTaskStatus(issue)- if err != nil {- return nil, err- }-- if status != api.TaskPendingApproval {- return nil, errors.Errorf("the status of issue %v is not pending approval", id)- }-- result, yes, err := ctl.sqlReviewTaskCheckRunFinished(issue)- if err != nil {- return nil, errors.Wrapf(err, "failed to get SQL review result for issue %v", id)- }- if yes {- return result, nil+ for _, check := range resp.PlanCheckRuns {+ if check.Status == v1pb.PlanCheckRun_DONE && check.Type == v1pb.PlanCheckRun_DATABASE_STATEMENT_ADVISE {+ return check, nil+ }}}return nil, nildiff --git a/backend/tests/sql_editor_test.go b/backend/tests/sql_editor_test.goindex c4af131c05..15f092be94 100644--- a/backend/tests/sql_editor_test.go+++ b/backend/tests/sql_editor_test.go@@ -2,10 +2,8 @@ package testsimport ("context"- "encoding/json""fmt""strconv"- "strings""testing""github.com/google/go-cmp/cmp"@@ -13,7 +11,6 @@ import ("google.golang.org/protobuf/testing/protocmp""google.golang.org/protobuf/types/known/durationpb"- api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/plugin/db"resourcemysql "github.com/bytebase/bytebase/backend/resources/mysql""github.com/bytebase/bytebase/backend/resources/postgres"@@ -121,8 +118,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {ctl := &controller{}dataDir := t.TempDir()ctx, err := ctl.StartServerWithExternalPg(ctx, &config{- dataDir: dataDir,- vcsProviderCreator: fake.NewGitLab,+ dataDir: dataDir,+ vcsProviderCreator: fake.NewGitLab,+ developmentUseV2Scheduler: true,})a.NoError(err)defer ctl.Close(ctx)@@ -139,8 +137,6 @@ func TestAdminQueryAffectedRows(t *testing.T) {// Create a project.project, err := ctl.createProject(ctx)a.NoError(err)- projectUID, err := strconv.Atoi(project.Uid)- a.NoError(err)prodEnvironment, err := ctl.getEnvironment(ctx, "prod")a.NoError(err)@@ -181,15 +177,13 @@ func TestAdminQueryAffectedRows(t *testing.T) {default:a.FailNow("unsupported db type")}- err = ctl.createDatabase(ctx, projectUID, instance, tt.databaseName, databaseOwner, nil)+ err = ctl.createDatabaseV2(ctx, project, instance, tt.databaseName, databaseOwner, nil)a.NoError(err)database, err := ctl.databaseServiceClient.GetDatabase(ctx, &v1pb.GetDatabaseRequest{Name: fmt.Sprintf("%s/databases/%s", instance.Name, tt.databaseName),})a.NoError(err)- databaseUID, err := strconv.Atoi(database.Uid)- a.NoError(err)sheet, err := ctl.sheetServiceClient.CreateSheet(ctx, &v1pb.CreateSheetRequest{Parent: project.Name,@@ -202,32 +196,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},})a.NoError(err)- sheetUID, err := strconv.Atoi(strings.TrimPrefix(sheet.Name, fmt.Sprintf("%s/sheets/", project.Name)))- a.NoError(err)- // Create an issue that updates database schema.- createContext, err := json.Marshal(&api.MigrationContext{- DetailList: []*api.MigrationDetail{- {- MigrationType: db.Migrate,- DatabaseID: databaseUID,- SheetID: sheetUID,- },- },- })- a.NoError(err)- issue, err := ctl.createIssue(api.IssueCreate{- ProjectID: projectUID,- Name: fmt.Sprintf("Prepare statements of database %q", tt.databaseName),- Type: api.IssueDatabaseSchemaUpdate,- Description: fmt.Sprintf("Prepare statements of database %q.", tt.databaseName),- AssigneeID: api.SystemBotID,- CreateContext: string(createContext),- })- a.NoError(err)- status, err := ctl.waitIssuePipeline(ctx, issue.ID)+ err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_MIGRATE)a.NoError(err)- a.Equal(api.TaskDone, status)results, err := ctl.adminQuery(ctx, instance, tt.databaseName, tt.query)a.NoError(err)diff --git a/backend/tests/sql_export_test.go b/backend/tests/sql_export_test.goindex f961a95f7b..5bfc391ceb 100644--- a/backend/tests/sql_export_test.go+++ b/backend/tests/sql_export_test.go@@ -2,7 +2,6 @@ package testsimport ("context"- "encoding/json""fmt""strconv""strings"@@ -13,7 +12,6 @@ import ("google.golang.org/protobuf/testing/protocmp""google.golang.org/protobuf/types/known/durationpb"- api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/plugin/db"resourcemysql "github.com/bytebase/bytebase/backend/resources/mysql""github.com/bytebase/bytebase/backend/resources/postgres"@@ -82,8 +80,9 @@ func TestSQLExport(t *testing.T) {ctl := &controller{}dataDir := t.TempDir()ctx, err := ctl.StartServerWithExternalPg(ctx, &config{- dataDir: dataDir,- vcsProviderCreator: fake.NewGitLab,+ dataDir: dataDir,+ vcsProviderCreator: fake.NewGitLab,+ developmentUseV2Scheduler: true,})a.NoError(err)defer ctl.Close(ctx)@@ -100,8 +99,6 @@ func TestSQLExport(t *testing.T) {// Create a project.project, err := ctl.createProject(ctx)a.NoError(err)- projectUID, err := strconv.Atoi(project.Uid)- a.NoError(err)prodEnvironment, err := ctl.getEnvironment(ctx, "prod")a.NoError(err)@@ -142,15 +139,13 @@ func TestSQLExport(t *testing.T) {default:a.FailNow("unsupported db type")}- err = ctl.createDatabase(ctx, projectUID, instance, tt.databaseName, databaseOwner, nil)+ err = ctl.createDatabaseV2(ctx, project, instance, tt.databaseName, databaseOwner, nil)a.NoError(err)database, err := ctl.databaseServiceClient.GetDatabase(ctx, &v1pb.GetDatabaseRequest{Name: fmt.Sprintf("%s/databases/%s", instance.Name, tt.databaseName),})a.NoError(err)- databaseUID, err := strconv.Atoi(database.Uid)- a.NoError(err)sheet, err := ctl.sheetServiceClient.CreateSheet(ctx, &v1pb.CreateSheetRequest{Parent: project.Name,@@ -163,32 +158,9 @@ func TestSQLExport(t *testing.T) {},})a.NoError(err)- sheetUID, err := strconv.Atoi(strings.TrimPrefix(sheet.Name, fmt.Sprintf("%s/sheets/", project.Name)))- a.NoError(err)- // Create an issue that updates database schema.- createContext, err := json.Marshal(&api.MigrationContext{- DetailList: []*api.MigrationDetail{- {- MigrationType: db.Migrate,- DatabaseID: databaseUID,- SheetID: sheetUID,- },- },- })- a.NoError(err)- issue, err := ctl.createIssue(api.IssueCreate{- ProjectID: projectUID,- Name: fmt.Sprintf("Prepare statements of database %q", tt.databaseName),- Type: api.IssueDatabaseSchemaUpdate,- Description: fmt.Sprintf("Prepare statements of database %q.", tt.databaseName),- AssigneeID: api.SystemBotID,- CreateContext: string(createContext),- })- a.NoError(err)- status, err := ctl.waitIssuePipeline(ctx, issue.ID)+ err = ctl.changeDatabase(ctx, project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_MIGRATE)a.NoError(err)- a.Equal(api.TaskDone, status)for _, databaseNameQuery := range []string{tt.databaseName, ""} {if databaseNameQuery == "" && tt.dbType != db.MySQL {diff --git a/backend/tests/sql_review_test.go b/backend/tests/sql_review_test.goindex 0e9a1eff52..350eb713a8 100644--- a/backend/tests/sql_review_test.go+++ b/backend/tests/sql_review_test.go@@ -12,7 +12,6 @@ import ("os""path/filepath""strconv"- "strings""testing"// Import pg driver.@@ -20,14 +19,13 @@ import ("github.com/google/go-cmp/cmp"_ "github.com/jackc/pgx/v4/stdlib""github.com/stretchr/testify/require"+ "google.golang.org/protobuf/encoding/protojson""google.golang.org/protobuf/testing/protocmp""google.golang.org/protobuf/types/known/durationpb""google.golang.org/protobuf/types/known/fieldmaskpb""gopkg.in/yaml.v3"- "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/resources/mysql""github.com/bytebase/bytebase/backend/resources/postgres""github.com/bytebase/bytebase/backend/tests/fake"@@ -35,20 +33,17 @@ import ()var (- noSQLReviewPolicy = []api.TaskCheckResult{+ noSQLReviewPolicy = []*v1pb.PlanCheckRun_Result{{- Status: api.TaskCheckStatusSuccess,- Namespace: api.BBNamespace,- Code: common.Ok.Int(),- Title: "OK",- Content: "",+ Status: v1pb.PlanCheckRun_Result_SUCCESS,+ Title: "OK",},})type test struct {Statement string- Result []api.TaskCheckResult+ Result []*v1pb.PlanCheckRun_ResultRun bool}@@ -86,9 +81,12 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {ctx := context.Background()ctl := &controller{}dataDir := t.TempDir()- ctx, err := ctl.StartServerWithExternalPg(ctx, &config{- dataDir: dataDir,- vcsProviderCreator: fake.NewGitLab,+ tests, err := readTestData(filepath)+ a.NoError(err)+ ctx, err = ctl.StartServerWithExternalPg(ctx, &config{+ dataDir: dataDir,+ vcsProviderCreator: fake.NewGitLab,+ developmentUseV2Scheduler: true,})a.NoError(err)defer ctl.Close(ctx)@@ -117,8 +115,6 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {// Create a project.project, err := ctl.createProject(ctx)a.NoError(err)- projectUID, err := strconv.Atoi(project.Uid)- a.NoError(err)prodEnvironment, err := ctl.getEnvironment(ctx, "prod")a.NoError(err)@@ -173,32 +169,20 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {})a.NoError(err)- err = ctl.createDatabase(ctx, projectUID, instance, databaseName, "bytebase", nil)+ err = ctl.createDatabaseV2(ctx, project, instance, databaseName, "bytebase", nil)a.NoError(err)database, err := ctl.databaseServiceClient.GetDatabase(ctx, &v1pb.GetDatabaseRequest{Name: fmt.Sprintf("%s/databases/%s", instance.Name, databaseName),})a.NoError(err)- databaseUID, err := strconv.Atoi(database.Uid)- a.NoError(err)-- yamlFile, err := os.Open(filepath)- a.NoError(err)-- tests := []test{}- byteValue, err := io.ReadAll(yamlFile)- a.NoError(yamlFile.Close())- a.NoError(err)- err = yaml.Unmarshal(byteValue, &tests)- a.NoError(err)for i, t := range tests {- result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, t.Statement, t.Run)+ result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, t.Statement, t.Run)if record {tests[i].Result = result} else {- a.Equal(t.Result, result)+ equalReviewResultProtos(a, t.Result, result, t.Statement)}}@@ -219,8 +203,8 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {})a.NoError(err)- result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, statements[0], false)- a.Equal(noSQLReviewPolicy, result)+ result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, statements[0], false)+ equalReviewResultProtos(a, noSQLReviewPolicy, result, "")// delete the SQL review policy_, err = ctl.orgPolicyServiceClient.DeletePolicy(ctx, &v1pb.DeletePolicyRequest{@@ -228,8 +212,8 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {})a.NoError(err)- result = createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, statements[0], false)- a.Equal(noSQLReviewPolicy, result)+ result = createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, statements[0], false)+ equalReviewResultProtos(a, noSQLReviewPolicy, result, "")}func TestSQLReviewForMySQL(t *testing.T) {@@ -295,10 +279,13 @@ func TestSQLReviewForMySQL(t *testing.T) {a := require.New(t)ctx := context.Background()ctl := &controller{}+ tests, err := readTestData(filepath)+ a.NoError(err)dataDir := t.TempDir()- ctx, err := ctl.StartServerWithExternalPg(ctx, &config{- dataDir: dataDir,- vcsProviderCreator: fake.NewGitLab,+ ctx, err = ctl.StartServerWithExternalPg(ctx, &config{+ dataDir: dataDir,+ vcsProviderCreator: fake.NewGitLab,+ developmentUseV2Scheduler: true,})a.NoError(err)defer ctl.Close(ctx)@@ -326,8 +313,6 @@ func TestSQLReviewForMySQL(t *testing.T) {// Create a project.project, err := ctl.createProject(ctx)a.NoError(err)- projectUID, err := strconv.Atoi(project.Uid)- a.NoError(err)prodEnvironment, err := ctl.getEnvironment(ctx, "prod")a.NoError(err)@@ -382,32 +367,20 @@ func TestSQLReviewForMySQL(t *testing.T) {})a.NoError(err)- err = ctl.createDatabase(ctx, projectUID, instance, databaseName, "", nil)+ err = ctl.createDatabaseV2(ctx, project, instance, databaseName, "", nil)a.NoError(err)database, err := ctl.databaseServiceClient.GetDatabase(ctx, &v1pb.GetDatabaseRequest{Name: fmt.Sprintf("%s/databases/%s", instance.Name, databaseName),})a.NoError(err)- databaseUID, err := strconv.Atoi(database.Uid)- a.NoError(err)-- yamlFile, err := os.Open(filepath)- a.NoError(err)-- tests := []test{}- byteValue, err := io.ReadAll(yamlFile)- a.NoError(yamlFile.Close())- a.NoError(err)- err = yaml.Unmarshal(byteValue, &tests)- a.NoError(err)for i, t := range tests {- result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, t.Statement, t.Run)+ result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, t.Statement, t.Run)if record {tests[i].Result = result} else {- a.Equal(t.Result, result, t.Statement)+ equalReviewResultProtos(a, t.Result, result, tests[i].Statement)}}@@ -434,7 +407,7 @@ func TestSQLReviewForMySQL(t *testing.T) {`INSERT INTO test(id, name) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');`,}for _, stmt := range initialStmts {- createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, stmt, true /* wait */)+ createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, stmt, true /* wait */)}countSQL := "SELECT count(*) FROM test WHERE 1=1;"dmlSQL := "INSERT INTO test SELECT * FROM " + valueTable@@ -446,7 +419,7 @@ func TestSQLReviewForMySQL(t *testing.T) {diff := cmp.Diff(wantQueryResult, originQueryResp.Results[0], protocmp.Transform(), protocmp.IgnoreMessages(&durationpb.Duration{}))a.Equal("", diff)- createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, dmlSQL, false /* wait */)+ createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, dmlSQL, false /* wait */)finalQueryResp, err := ctl.sqlServiceClient.Query(ctx, &v1pb.QueryRequest{Name: instance.Name, ConnectionDatabase: databaseName, Statement: countSQL,@@ -472,13 +445,55 @@ func TestSQLReviewForMySQL(t *testing.T) {})a.NoError(err)- result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, databaseUID, projectUID, project.Name, statements[0], false)- a.Equal(noSQLReviewPolicy, result)+ result := createIssueAndReturnSQLReviewResult(ctx, a, ctl, project, database, statements[0], false)+ equalReviewResultProtos(a, noSQLReviewPolicy, result, "")+}++func readTestData(path string) ([]test, error) {+ yamlFile, err := os.Open(path)+ if err != nil {+ return nil, err+ }+ defer yamlFile.Close()+ byteValue, err := io.ReadAll(yamlFile)+ if err != nil {+ return nil, err+ }+ type yamlStruct struct {+ Statement string+ Result []any+ Run bool+ }+ var yamlTests []yamlStruct+ if err := yaml.Unmarshal(byteValue, &yamlTests); err != nil {+ return nil, err+ }++ var tests []test+ for _, yamlTest := range yamlTests {+ t := test{+ Statement: yamlTest.Statement,+ Run: yamlTest.Run,+ }+ for _, r := range yamlTest.Result {+ jsonData, err := json.MarshalIndent(r, "", " ")+ if err != nil {+ return nil, err+ }+ result := &v1pb.PlanCheckRun_Result{}+ if err := protojson.Unmarshal(jsonData, result); err != nil {+ return nil, err+ }+ t.Result = append(t.Result, result)+ }+ tests = append(tests, t)+ }+ return tests, nil}-func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Assertions, ctl *controller, databaseID int, projectID int, projectName, statement string, wait bool) []api.TaskCheckResult {+func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Assertions, ctl *controller, project *v1pb.Project, database *v1pb.Database, statement string, wait bool) []*v1pb.PlanCheckRun_Result {sheet, err := ctl.sheetServiceClient.CreateSheet(ctx, &v1pb.CreateSheetRequest{- Parent: projectName,+ Parent: project.Name,Sheet: &v1pb.Sheet{Title: "statement",Content: []byte(statement),@@ -488,40 +503,64 @@ func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Asserti},})a.NoError(err)- sheetUID, err := strconv.Atoi(strings.TrimPrefix(sheet.Name, fmt.Sprintf("%s/sheets/", projectName)))- a.NoError(err)- createContext, err := json.Marshal(&api.MigrationContext{- DetailList: []*api.MigrationDetail{- {- MigrationType: db.Migrate,- DatabaseID: databaseID,- SheetID: sheetUID,+ plan, err := ctl.rolloutServiceClient.CreatePlan(ctx, &v1pb.CreatePlanRequest{+ Parent: project.Name,+ Plan: &v1pb.Plan{+ Steps: []*v1pb.Plan_Step{+ {+ Specs: []*v1pb.Plan_Spec{+ {+ Config: &v1pb.Plan_Spec_ChangeDatabaseConfig{+ ChangeDatabaseConfig: &v1pb.Plan_ChangeDatabaseConfig{+ Target: database.Name,+ Sheet: sheet.Name,+ Type: v1pb.Plan_ChangeDatabaseConfig_MIGRATE,+ },+ },+ },+ },+ },},},})a.NoError(err)- issue, err := ctl.createIssue(api.IssueCreate{- ProjectID: projectID,- Name: "update schema for database",- Type: api.IssueDatabaseSchemaUpdate,- Description: "This updates the schema of database",- AssigneeID: api.SystemBotID,- CreateContext: string(createContext),- })- a.NoError(err)-- result, err := ctl.GetSQLReviewResult(issue.ID)+ result, err := ctl.GetSQLReviewResult(ctx, plan)a.NoError(err)if wait {- a.Equal(1, len(result))- a.Equal(common.Ok.Int(), result[0].Code, result[0])- status, err := ctl.waitIssuePipeline(ctx, issue.ID)+ a.NotNil(result)+ a.Len(result.Results, 1)+ a.Equal(v1pb.PlanCheckRun_Result_SUCCESS, result.Results[0].Status)+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})+ a.NoError(err)+ _, err = ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{+ Parent: project.Name,+ Issue: &v1pb.Issue{+ Type: v1pb.Issue_DATABASE_CHANGE,+ Title: fmt.Sprintf("change database %s", database.Name),+ Description: fmt.Sprintf("change database %s", database.Name),+ Plan: plan.Name,+ Rollout: rollout.Name,+ Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),+ },+ })+ a.NoError(err)+ err = ctl.waitRollout(ctx, rollout.Name)a.NoError(err)- a.Equal(api.TaskDone, status)}- return result+ return result.Results+}++func equalReviewResultProtos(a *require.Assertions, want, got []*v1pb.PlanCheckRun_Result, message string) {+ a.Equal(len(want), len(got))+ for i := 0; i < len(want); i++ {+ wantJSON, err := protojson.Marshal(want[i])+ a.NoError(err)+ gotJSON, err := protojson.Marshal(got[i])+ a.NoError(err)+ a.Equal(string(wantJSON), string(gotJSON), message)+ }}diff --git a/backend/tests/test-data/sql_review_mysql.yaml b/backend/tests/test-data/sql_review_mysql.yamlindex f648f4c86b..24bec153a1 100644--- a/backend/tests/test-data/sql_review_mysql.yaml+++ b/backend/tests/test-data/sql_review_mysql.yaml@@ -1,470 +1,405 @@- statement: CREATE TABLE user(id INT PRIMARY KEY COMMENT 'comment',name VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'comment',room_id INT NOT NULL DEFAULT 0 COMMENT 'comment',creator_id INT NOT NULL DEFAULT 0 COMMENT 'comment',created_ts TIMESTAMP NOT NULL DEFAULT NOW() COMMENT 'comment',updater_id INT NOT NULL DEFAULT 0 COMMENT 'comment',updated_ts TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',INDEX idx_user_name(name),UNIQUE KEY uk_user_id_name(id, name)) ENGINE = INNODB COMMENT 'comment'result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OK- content: ""- line: 0- details: ""run: false- statement: CREATE TABLE user(id);result:- - namespace: bb.advisor- code: 201- status: ERROR+ - status: 1title: Syntax errorcontent: |-Syntax error at line 1:20related text: CREATE TABLE user(id)- line: 1- column: 20- details: ""+ sql_review_report:+ code: 201+ line: 1+ column: 20run: false- statement: CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_binresult:- - namespace: bb.advisor- code: 501- status: ERROR+ - status: 1title: engine.mysql.use-innodbcontent: |-"CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;" doesn't use InnoDB engine- line: 2- details: ""- - namespace: bb.advisor- code: 601- status: ERROR+ sql_review_report:+ code: 501+ line: 2+ - status: 1title: table.require-pkcontent: Table `userTable` requires PRIMARY KEY- line: 2- details: ""- - namespace: bb.advisor- code: 602- status: ERROR+ sql_review_report:+ code: 601+ line: 2+ - status: 1title: table.no-foreign-keycontent: Foreign key is not allowed in the table `userTable`- line: 1- details: ""- - namespace: bb.advisor- code: 411- status: ERROR+ sql_review_report:+ code: 602+ line: 1+ - status: 1title: column.type-disallow-listcontent: Disallow column type JSON but column `userTable`.`json_content` is- line: 1- details: ""- - namespace: bb.advisor- code: 301- status: WARN+ sql_review_report:+ code: 411+ line: 1+ - status: 2title: naming.tablecontent: '`userTable` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'- line: 2- details: ""- - namespace: bb.advisor- code: 302- status: WARN+ sql_review_report:+ code: 301+ line: 2+ - status: 2title: naming.columncontent: '`userTable`.`roomId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'- line: 1- details: ""- - namespace: bb.advisor- code: 303- status: WARN+ sql_review_report:+ code: 302+ line: 1+ - status: 2title: naming.index.idxcontent: Index in table `userTable` mismatches the naming convention, expect "^$|^idx_userTable_name$" but found `idx1`- line: 1- details: ""- - namespace: bb.advisor- code: 304- status: WARN+ sql_review_report:+ code: 303+ line: 1+ - status: 2title: naming.index.ukcontent: Unique key in table `userTable` mismatches the naming convention, expect "^$|^uk_userTable_id_name$" but found `uk1`- line: 1- details: ""- - namespace: bb.advisor- code: 305- status: WARN+ sql_review_report:+ code: 304+ line: 1+ - status: 2title: naming.index.fkcontent: Foreign key in table `userTable` mismatches the naming convention, expect "^$|^fk_userTable_roomId_room_id$" but found `fk1`- line: 1- details: ""- - namespace: bb.advisor- code: 605- status: WARN+ sql_review_report:+ code: 305+ line: 1+ - status: 2title: table.commentcontent: Table `userTable` requires comments- line: 2- details: ""- - namespace: bb.advisor- code: 401- status: WARN+ sql_review_report:+ code: 605+ line: 2+ - status: 2title: column.requiredcontent: "Table `userTable` requires columns: created_ts, creator_id, updated_ts, updater_id"- line: 2- details: ""- - namespace: bb.advisor- code: 402- status: WARN+ sql_review_report:+ code: 401+ line: 2+ - status: 2title: column.no-nullcontent: "`userTable`.`name` cannot have NULL value"- line: 1- details: ""- - namespace: bb.advisor- code: 402- status: WARN+ sql_review_report:+ code: 402+ line: 1+ - status: 2title: column.no-nullcontent: "`userTable`.`roomId` cannot have NULL value"- line: 1- details: ""- - namespace: bb.advisor- code: 404- status: WARN+ sql_review_report:+ code: 402+ line: 1+ - status: 2title: column.set-default-for-not-nullcontent: Column `userTable`.`id` is NOT NULL but doesn't have DEFAULT- line: 1- details: ""- - namespace: bb.advisor- code: 408- status: WARN+ sql_review_report:+ code: 404+ line: 1+ - status: 2title: column.commentcontent: Column `userTable`.`id` requires comments- line: 1- details: ""- - namespace: bb.advisor- code: 408- status: WARN+ sql_review_report:+ code: 408+ line: 1+ - status: 2title: column.commentcontent: Column `userTable`.`name` requires comments- line: 1- details: ""- - namespace: bb.advisor- code: 408- status: WARN+ sql_review_report:+ code: 408+ line: 1+ - status: 2title: column.commentcontent: Column `userTable`.`roomId` requires comments- line: 1- details: ""- - namespace: bb.advisor- code: 414- status: WARN+ sql_review_report:+ code: 408+ line: 1+ - status: 2title: column.disallow-set-charsetcontent: |-Disallow set column charset but "CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;" does- line: 2- details: ""- - namespace: bb.advisor- code: 419- status: WARN+ sql_review_report:+ code: 414+ line: 2+ - status: 2title: column.current-time-count-limitcontent: Table `userTable` has 2 ON UPDATE CURRENT_TIMESTAMP() columns. The count greater than 1.- line: 2- details: ""- - namespace: bb.advisor- code: 420- status: WARN+ sql_review_report:+ code: 419+ line: 2+ - status: 2title: column.require-defaultcontent: Column `userTable`.`id` doesn't have DEFAULT.- line: 1- details: ""- - namespace: bb.advisor- code: 420- status: WARN+ sql_review_report:+ code: 420+ line: 1+ - status: 2title: column.require-defaultcontent: Column `userTable`.`name` doesn't have DEFAULT.- line: 1- details: ""- - namespace: bb.advisor- code: 420- status: WARN+ sql_review_report:+ code: 420+ line: 1+ - status: 2title: column.require-defaultcontent: Column `userTable`.`roomId` doesn't have DEFAULT.- line: 1- details: ""- - namespace: bb.advisor- code: 804- status: WARN+ sql_review_report:+ code: 420+ line: 1+ - status: 2title: index.type-no-blobcontent: Columns in index must not be BLOB but `userTable`.`content` is blob- line: 1- details: ""- - namespace: bb.advisor- code: 1001- status: WARN+ sql_review_report:+ code: 804+ line: 1+ - status: 2title: system.charset.allowlistcontent: |-"CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;" used disabled charset 'ascii'- line: 1- details: ""- - namespace: bb.advisor- code: 1201- status: WARN+ sql_review_report:+ code: 1001+ line: 1+ - status: 2title: system.collation.allowlistcontent: |-"CREATE TABLE userTable(id INT NOT NULL,name VARCHAR(255) CHARSET ascii,roomId INT,time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',content BLOB NOT NULL COMMENT 'comment',json_content JSON NOT NULL COMMENT 'comment',INDEX idx1(name),UNIQUE KEY uk1(id, name),FOREIGN KEY fk1(roomId) REFERENCES room(id),INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;" used disabled collation 'latin1_bin'- line: 2- details: ""+ sql_review_report:+ code: 1201+ line: 2run: false- statement: CREATE TABLE t_auto(auto_id varchar(20) AUTO_INCREMENT PRIMARY KEY COMMENT 'COMMENT') auto_increment = 2 COMMENT 'comment'result:- - namespace: bb.advisor- code: 410- status: ERROR+ - status: 1title: column.auto-increment-must-integercontent: Auto-increment column `t_auto`.`auto_id` requires integer type- line: 2- details: ""- - namespace: bb.advisor- code: 307- status: WARN+ sql_review_report:+ code: 410+ line: 2+ - status: 2title: naming.column.auto-incrementcontent: '`t_auto`.`auto_id` mismatches auto_increment column naming convention, naming format should be "^id$"'- line: 1- details: ""- - namespace: bb.advisor- code: 401- status: WARN+ sql_review_report:+ code: 307+ line: 1+ - status: 2title: column.requiredcontent: "Table `t_auto` requires columns: created_ts, creator_id, id, updated_ts, updater_id"- line: 2- details: ""- - namespace: bb.advisor- code: 416- status: WARN+ sql_review_report:+ code: 401+ line: 2+ - status: 2title: column.auto-increment-initial-valuecontent: The initial auto-increment value in table `t_auto` is 2, which doesn't equal 20- line: 2- details: ""- - namespace: bb.advisor- code: 417- status: WARN+ sql_review_report:+ code: 416+ line: 2+ - status: 2title: column.auto-increment-must-unsignedcontent: Auto-increment column `t_auto`.`auto_id` is not UNSIGNED type- line: 2- details: ""- - namespace: bb.advisor- code: 803- status: WARN+ sql_review_report:+ code: 417+ line: 2+ - status: 2title: index.pk-type-limitcontent: Columns in primary key must be INT/BIGINT but `t_auto`.`auto_id` is varchar(20)- line: 1- details: ""+ sql_review_report:+ code: 803+ line: 1run: false- statement: " DELETE FROM tech_book"result:- - namespace: bb.advisor- code: 202- status: ERROR+ - status: 1title: statement.where.requirecontent: |-" DELETE FROM tech_book;" requires WHERE clause- line: 2- details: ""- - namespace: bb.advisor- code: 208- status: ERROR+ sql_review_report:+ code: 202+ line: 2+ - status: 1title: statement.dml-dry-runcontent: |-" DELETE FROM tech_book;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 209- status: WARN+ sql_review_report:+ code: 208+ line: 2+ - status: 2title: statement.affected-row-limitcontent: |-" DELETE FROM tech_book;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""+ sql_review_report:+ code: 209+ line: 2run: false- statement: DELETE FROM tech_book WHERE name like `%abc`result:- - namespace: bb.advisor- code: 204- status: ERROR+ - status: 1title: statement.where.no-leading-wildcard-likecontent: |-"DELETE FROM tech_book WHERE name like `%abc`;" uses leading wildcard LIKE- line: 2- details: ""- - namespace: bb.advisor- code: 208- status: ERROR+ sql_review_report:+ code: 204+ line: 2+ - status: 1title: statement.dml-dry-runcontent: |-"DELETE FROM tech_book WHERE name like `%abc`;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 209- status: WARN+ sql_review_report:+ code: 208+ line: 2+ - status: 2title: statement.affected-row-limitcontent: |-"DELETE FROM tech_book WHERE name like `%abc`;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""+ sql_review_report:+ code: 209+ line: 2run: false- statement: " INSERT INTO t_copy SELECT * FROM t"result:- - namespace: bb.advisor- code: 203- status: ERROR+ - status: 1title: statement.select.no-select-allcontent: |-" INSERT INTO t_copy SELECT * FROM t;" uses SELECT all- line: 2- details: ""- - namespace: bb.advisor- code: 202- status: ERROR+ sql_review_report:+ code: 203+ line: 2+ - status: 1title: statement.where.requirecontent: |-" INSERT INTO t_copy SELECT * FROM t;" requires WHERE clause- line: 2- details: ""- - namespace: bb.advisor- code: 208- status: ERROR+ sql_review_report:+ code: 202+ line: 2+ - status: 1title: statement.dml-dry-runcontent: |-" INSERT INTO t_copy SELECT * FROM t;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.t_copy' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 1101- status: WARN+ sql_review_report:+ code: 208+ line: 2+ - status: 2title: statement.insert.row-limitcontent: |-" INSERT INTO t_copy SELECT * FROM t;" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.t_copy' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 1107- status: WARN+ sql_review_report:+ code: 1101+ line: 2+ - status: 2title: statement.insert.must-specify-columncontent: |-The INSERT statement must specify columns but " INSERT INTO t_copy SELECT * FROM t;" does not- line: 2- details: ""+ sql_review_report:+ code: 1107+ line: 2run: false- statement: " INSERT INTO t VALUES (1, 1, now(), 1, now())"result:- - namespace: bb.advisor- code: 208- status: ERROR+ - status: 1title: statement.dml-dry-runcontent: |-" INSERT INTO t VALUES (1, 1, now(), 1, now());" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.t' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 1107- status: WARN+ sql_review_report:+ code: 208+ line: 2+ - status: 2title: statement.insert.must-specify-columncontent: |-The INSERT statement must specify columns but " INSERT INTO t VALUES (1, 1, now(), 1, now());" does not- line: 2- details: ""+ sql_review_report:+ code: 1107+ line: 2run: false- statement: DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = 'bytebase')result:- - namespace: bb.advisor- code: 208- status: ERROR+ - status: 1title: statement.dml-dry-runcontent: |-"DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = 'bytebase');" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""- - namespace: bb.advisor- code: 209- status: WARN+ sql_review_report:+ code: 208+ line: 2+ - status: 2title: statement.affected-row-limitcontent: |-"DELETE FROM tech_book WHERE id = (SELECT max(id) FROM tech_book WHERE name = 'bytebase');" dry runs failed: Error 1146 (42S02): Table 'testsqlreview.tech_book' doesn't exist- line: 2- details: ""+ sql_review_report:+ code: 209+ line: 2run: false- statement: COMMIT;result:- - namespace: bb.advisor- code: 206- status: ERROR+ - status: 1title: statement.disallow-commitcontent: |-Commit is not allowed, related statement: "COMMIT;"- line: 2- details: ""+ sql_review_report:+ code: 206+ line: 2run: false- statement: CREATE TABLE user(id INT PRIMARY KEY COMMENT 'comment',name VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'comment',room_id INT NOT NULL DEFAULT 0 COMMENT 'comment',creator_id INT NOT NULL DEFAULT 0 COMMENT 'comment',created_ts TIMESTAMP NOT NULL DEFAULT NOW() COMMENT 'comment',updater_id INT NOT NULL DEFAULT 0 COMMENT 'comment',updated_ts TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',INDEX idx_user_name(name),UNIQUE KEY uk_user_id_name(id, name)) ENGINE = INNODB COMMENT 'comment'result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0- details: ""run: true- statement: INSERT INTO user(id, name) values (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0- details: ""run: true- statement: DELETE FROM user WHERE id < 10result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0- details: ""run: false- statement: INSERT INTO user(id, name) values (6, 'f'), (7, 'g'), (8, 'h'), (9, 'i'), (10, 'j')result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0- details: ""run: true- statement: DELETE FROM user WHERE id <= 10result:- - namespace: bb.advisor- code: 209- status: WARN+ - status: 2title: statement.affected-row-limitcontent: |-"DELETE FROM user WHERE id <= 10;" affected 10 rows. The count exceeds 5.- line: 2- details: ""+ sql_review_report:+ code: 209+ line: 2run: false- statement: |-INSERT INTO user(id, name) SELECT id, name FROM (SELECT 1 AS id, 'a' AS name WHERE 1=1 UNION ALL@@ -478,9 +413,7 @@SELECT 9 AS id, 'i' AS name WHERE 1=1 UNION ALLSELECT 10 AS id, 'j' AS name WHERE 1=1) value_table WHERE 1=1result:- - namespace: bb.advisor- code: 1101- status: WARN+ - status: 2title: statement.insert.row-limitcontent: |-"INSERT INTO user(id, name) SELECT id, name FROM (SELECT 1 AS id, 'a' AS name WHERE 1=1 UNION ALL@@ -494,89 +427,81 @@SELECT 9 AS id, 'i' AS name WHERE 1=1 UNION ALLSELECT 10 AS id, 'j' AS name WHERE 1=1) value_table WHERE 1=1;" inserts 10 rows. The count exceeds 5.- line: 11- details: ""+ sql_review_report:+ code: 1101+ line: 11run: false- statement: INSERT INTO user(id, name) SELECT id, name FROM user WHERE id=1 LIMIT 1result:- - namespace: bb.advisor- code: 1103- status: WARN+ - status: 2title: statement.disallow-limitcontent: |-LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "INSERT INTO user(id, name) SELECT id, name FROM user WHERE id=1 LIMIT 1;" uses- line: 2- details: ""+ sql_review_report:+ code: 1103+ line: 2run: false- statement: " ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;"result:- - namespace: bb.advisor- code: 608- status: WARN+ - status: 2title: table.disallow-partitioncontent: |-Table partition is forbidden, but " ALTER TABLE user PARTITION BY HASH(id) PARTITIONS 8;" creates- line: 2- details: ""+ sql_review_report:+ code: 608+ line: 2run: false- statement: |-ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '' COMMENT 'COMMENT' FIRST;ALTER TABLE user ADD COLUMN c_column int NOT NULL DEFAULT 0 COMMENT 'comment';result:- - namespace: bb.advisor- code: 207- status: WARN+ - status: 2title: statement.merge-alter-tablecontent: There are 2 statements to modify table `user`- line: 3- details: ""- - namespace: bb.advisor- code: 403- status: WARN+ sql_review_report:+ code: 207+ line: 3+ - status: 2title: column.disallow-change-typecontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" changes column type'- line: 1- details: ""- - namespace: bb.advisor- code: 406- status: WARN+ sql_review_report:+ code: 403+ line: 1+ - status: 2title: column.disallow-changecontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" contains CHANGE COLUMN statement'- line: 1- details: ""- - namespace: bb.advisor- code: 407- status: WARN+ sql_review_report:+ code: 406+ line: 1+ - status: 2title: column.disallow-changing-ordercontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" changes column order'- line: 1- details: ""- - namespace: bb.advisor- code: 111- status: WARN+ sql_review_report:+ code: 407+ line: 1+ - status: 2title: schema.backward-compatibilitycontent: '"ALTER TABLE user CHANGE name name varchar(320) NOT NULL DEFAULT '''' COMMENT ''COMMENT'' FIRST;" may cause incompatibility with the existing data and code'- line: 1- details: ""+ sql_review_report:+ code: 111+ line: 1run: false- statement: " DROP TABLE user;"result:- - namespace: bb.advisor- code: 603- status: ERROR+ - status: 1title: table.drop-naming-conventioncontent: '`user` mismatches drop table naming convention, naming format should be "_delete$"'- line: 2- details: ""- - namespace: bb.advisor- code: 103- status: WARN+ sql_review_report:+ code: 603+ line: 2+ - status: 2title: schema.backward-compatibilitycontent: |-" DROP TABLE user;" may cause incompatibility with the existing data and code- line: 2- details: ""+ sql_review_report:+ code: 103+ line: 2run: falsediff --git a/backend/tests/test-data/sql_review_pg.yaml b/backend/tests/test-data/sql_review_pg.yamlindex 555cdc9dfa..3bdd29b780 100644--- a/backend/tests/test-data/sql_review_pg.yaml+++ b/backend/tests/test-data/sql_review_pg.yaml@@ -11,21 +11,18 @@CONSTRAINT uk_user_id_name UNIQUE (id, name))result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0title: OK- content: ""- line: 0+ status: 3run: false- statement: CREATE TABLE user(id);result:- - namespace: bb.advisor- code: 201- status: ERROR+ - status: 1title: Syntax errorcontent: syntax error at or near "user"- line: 1+ sql_review_report:+ code: 201+ line: 1run: false- statement: |-CREATE TABLE "userTable"(@@ -36,15 +33,13 @@CONSTRAINT fk1 FOREIGN KEY ("roomId") REFERENCES room(id))result:- - namespace: bb.advisor- code: 601- status: ERROR+ - status: 1title: table.require-pkcontent: 'Table "public"."userTable" requires PRIMARY KEY, related statement: "CREATE TABLE \"userTable\"(\n id INT,\n name VARCHAR(255),\n \"roomId\" INT,\n CONSTRAINT uk1 UNIQUE (id, name),\n CONSTRAINT fk1 FOREIGN KEY (\"roomId\") REFERENCES room(id)\n )"'- line: 7- - namespace: bb.advisor- code: 602- status: ERROR+ sql_review_report:+ code: 601+ line: 7+ - status: 1title: table.no-foreign-keycontent: |-Foreign key is not allowed in the table "public"."userTable", related statement: "CREATE TABLE "userTable"(@@ -54,91 +49,89 @@CONSTRAINT uk1 UNIQUE (id, name),CONSTRAINT fk1 FOREIGN KEY ("roomId") REFERENCES room(id))"- line: 7- - namespace: bb.advisor- code: 301- status: WARN+ sql_review_report:+ code: 602+ line: 7+ - status: 2title: naming.tablecontent: '"userTable" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'- line: 7- - namespace: bb.advisor- code: 302- status: WARN+ sql_review_report:+ code: 301+ line: 7+ - status: 2title: naming.columncontent: '"userTable"."roomId" mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'- line: 4- - namespace: bb.advisor- code: 304- status: WARN+ sql_review_report:+ code: 302+ line: 4+ - status: 2title: naming.index.ukcontent: Unique key in table "userTable" mismatches the naming convention, expect "^$|^uk_userTable_id_name$" but found "uk1"- line: 5- - namespace: bb.advisor- code: 305- status: WARN+ sql_review_report:+ line: 5+ code: 304+ - status: 2title: naming.index.fkcontent: Foreign key in table "userTable" mismatches the naming convention, expect "^$|^fk_userTable_roomId_room_id$" but found "fk1"- line: 6- - namespace: bb.advisor- code: 401- status: WARN+ sql_review_report:+ code: 305+ line: 6+ - status: 2title: column.requiredcontent: 'Table "userTable" requires columns: created_ts, creator_id, updated_ts, updater_id'- line: 7- - namespace: bb.advisor- code: 402- status: WARN+ sql_review_report:+ code: 401+ line: 7+ - status: 2title: column.no-nullcontent: Column "id" in "public"."userTable" cannot have NULL value- line: 2- - namespace: bb.advisor- code: 402- status: WARN+ sql_review_report:+ line: 2+ code: 402+ - status: 2title: column.no-nullcontent: Column "name" in "public"."userTable" cannot have NULL value- line: 3- - namespace: bb.advisor- code: 402- status: WARN+ sql_review_report:+ code: 402+ line: 3+ - status: 2title: column.no-nullcontent: Column "roomId" in "public"."userTable" cannot have NULL value- line: 4+ sql_review_report:+ code: 402+ line: 4run: false- statement: DELETE FROM tresult:- - namespace: bb.advisor- code: 202- status: ERROR+ - status: 1title: statement.where.requirecontent: '"DELETE FROM t" requires WHERE clause'- line: 1+ sql_review_report:+ code: 202+ line: 1run: false- statement: DELETE FROM t WHERE a like '%abc'result:- - namespace: bb.advisor- code: 204- status: ERROR+ - status: 1title: statement.where.no-leading-wildcard-likecontent: '"DELETE FROM t WHERE a like ''%abc''" uses leading wildcard LIKE'- line: 1+ sql_review_report:+ code: 204+ line: 1run: false- statement: DELETE FROM t WHERE a = (SELECT max(id) FROM "user" WHERE name = 'bytebase')result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0run: false- statement: INSERT INTO t VALUES (1), (2)result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0run: false- statement: |-CREATE TABLE tech_book(@@ -150,19 +143,17 @@CONSTRAINT pk_tech_book_id PRIMARY KEY (id))result:- - namespace: bb.core- code: 0- status: SUCCESS+ - code: 0+ status: 3title: OKcontent: ""- line: 0run: true- statement: ALTER INDEX pk_tech_book_id RENAME TO pk1result:- - namespace: bb.advisor- code: 306- status: WARN+ - status: 2title: naming.index.pkcontent: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id$" but found "pk1"- line: 1+ sql_review_report:+ code: 306+ line: 1run: false