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: change project (#12125)
Danny Xud5ded50f5c73
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex ad505092a9..22b5c1c772 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -939,7 +939,7 @@ func (s *DatabaseService) ListChangeHistories(ctx context.Context, request *v1pbif err != nil {return nil, status.Errorf(codes.Internal, "failed to get next page token, error: %v", err)}- converted, err := convertToChangeHistories(changeHistories[:limit])+ converted, err := s.convertToChangeHistories(ctx, changeHistories[:limit])if err != nil {return nil, status.Errorf(codes.Internal, "failed to convert change histories, error: %v", err)}@@ -950,7 +950,7 @@ func (s *DatabaseService) ListChangeHistories(ctx context.Context, request *v1pb}// no subsequent pages- converted, err := convertToChangeHistories(changeHistories)+ converted, err := s.convertToChangeHistories(ctx, changeHistories)if err != nil {return nil, status.Errorf(codes.Internal, "failed to convert change histories, error: %v", err)}@@ -1012,7 +1012,7 @@ func (s *DatabaseService) GetChangeHistory(ctx context.Context, request *v1pb.Geif len(changeHistory) > 1 {return nil, status.Errorf(codes.Internal, "expect to find one change history, got %d", len(changeHistory))}- converted, err := convertToChangeHistory(changeHistory[0])+ converted, err := s.convertToChangeHistory(ctx, changeHistory[0])if err != nil {return nil, status.Errorf(codes.Internal, "failed to convert change history, error: %v", err)}@@ -1172,10 +1172,10 @@ func (s *DatabaseService) getParserEngine(ctx context.Context, request *v1pb.Difreturn engine, nil}-func convertToChangeHistories(h []*store.InstanceChangeHistoryMessage) ([]*v1pb.ChangeHistory, error) {+func (s *DatabaseService) convertToChangeHistories(ctx context.Context, h []*store.InstanceChangeHistoryMessage) ([]*v1pb.ChangeHistory, error) {var changeHistories []*v1pb.ChangeHistoryfor _, history := range h {- converted, err := convertToChangeHistory(history)+ converted, err := s.convertToChangeHistory(ctx, history)if err != nil {return nil, errors.Wrapf(err, "failed to convert change history")}@@ -1184,7 +1184,7 @@ func convertToChangeHistories(h []*store.InstanceChangeHistoryMessage) ([]*v1pb.return changeHistories, nil}-func convertToChangeHistory(h *store.InstanceChangeHistoryMessage) (*v1pb.ChangeHistory, error) {+func (s *DatabaseService) convertToChangeHistory(ctx context.Context, h *store.InstanceChangeHistoryMessage) (*v1pb.ChangeHistory, error) {v1pbHistory := &v1pb.ChangeHistory{Name: fmt.Sprintf("%s%s/%s%s/%s%v", common.InstanceNamePrefix, h.InstanceID, common.DatabaseIDPrefix, h.DatabaseName, common.ChangeHistoryPrefix, h.UID),Uid: h.UID,@@ -1207,11 +1207,19 @@ func convertToChangeHistory(h *store.InstanceChangeHistoryMessage) (*v1pb.ChangeExecutionDuration: durationpb.New(time.Duration(h.ExecutionDurationNs)),Issue: "",}- if h.SheetID != nil {- v1pbHistory.StatementSheet = fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, h.IssueProjectID, common.SheetIDPrefix, *h.SheetID)+ var projectID string+ if h.ProjectUID != nil {+ p, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{UID: h.ProjectUID})+ if err != nil {+ return nil, err+ }+ projectID = p.ResourceID+ }+ if h.SheetID != nil && projectID != "" {+ v1pbHistory.StatementSheet = fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, projectID, common.SheetIDPrefix, *h.SheetID)}- if h.IssueUID != nil {- v1pbHistory.Issue = fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, h.IssueProjectID, common.IssueNamePrefix, *h.IssueUID)+ if h.IssueUID != nil && projectID != "" {+ v1pbHistory.Issue = fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, projectID, common.IssueNamePrefix, *h.IssueUID)}if h.Payload != nil && h.Payload.ChangedResources != nil {v1pbHistory.ChangedResources = convertToChangedResources(h.Payload.ChangedResources)diff --git a/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql b/backend/migrator/migration/prod/2.18/0007##change_issue_project.sqlnew file mode 100644index 0000000000..2610a5c26a--- /dev/null+++ b/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql@@ -0,0 +1,2 @@+ALTER TABLE instance_change_history ADD COLUMN project_id INTEGER REFERENCES project (id);+UPDATE instance_change_history SET project_id = (SELECT project_id FROM issue WHERE issue.id = instance_change_history.issue_id) WHERE instance_change_history.issue_id IS NOT NULL;\ No newline at end of filediff --git a/backend/migrator/migration/prod/LATEST.sql b/backend/migrator/migration/prod/LATEST.sqlindex 1efda2a53c..36fb127ad5 100644--- a/backend/migrator/migration/prod/LATEST.sql+++ b/backend/migrator/migration/prod/LATEST.sql@@ -617,6 +617,7 @@ CREATE TABLE instance_change_history (instance_id INTEGER REFERENCES instance (id),-- NULL means an instance-level change.database_id INTEGER REFERENCES db (id),+ project_id INTEGER REFERENCES project (id),-- issue_id is nullable because this field is backfilled and may not be present.issue_id INTEGER REFERENCES issue (id),-- Record the client version creating this change history. For Bytebase, we use its binary release version. Different Bytebase release mightdiff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.goindex 5339323634..ae5cf84cf7 100644--- a/backend/migrator/migrator.go+++ b/backend/migrator/migrator.go@@ -120,6 +120,7 @@ func initializeSchema(ctx context.Context, storeInstance *store.Store, metadataDCreatorID: api.SystemBotID,InstanceUID: nil,DatabaseUID: nil,+ ProjectUID: nil,IssueUID: nil,ReleaseVersion: serverVersion,// Sequence starts from 1.diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex 18a0e93eea..e71f5ac16a 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -230,5 +230,5 @@ func TestMigrationCompatibility(t *testing.T) {func TestGetCutoffVersion(t *testing.T) {releaseVersion, err := getProdCutoffVersion()require.NoError(t, err)- require.Equal(t, semver.MustParse("2.18.6"), releaseVersion)+ require.Equal(t, semver.MustParse("2.18.7"), releaseVersion)}diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.goindex 56e788b776..e4e85d27bb 100644--- a/backend/plugin/db/driver.go+++ b/backend/plugin/db/driver.go@@ -137,6 +137,7 @@ type MigrationInfo struct {// InstanceID nil is metadata database.InstanceID *intDatabaseID *int+ ProjectUID *intIssueUID *intCreatorID intdiff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.goindex 8ae6c4e417..9a4ed95491 100644--- a/backend/runner/taskrun/database_create_executor.go+++ b/backend/runner/taskrun/database_create_executor.go@@ -405,6 +405,8 @@ func (exec *DatabaseCreateExecutor) createInitialSchema(ctx context.Context, drilog.BBError(err),)}+ mi.ProjectUID = &project.UID+ // TODO(d): how could issue be nil?if issue == nil {err := errors.Errorf("failed to fetch containing issue for composing the migration info, issue not found with pipeline ID %v", task.PipelineID)slog.Error(err.Error(),diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.goindex dd79a14e77..abaf712d97 100644--- a/backend/runner/taskrun/executor.go+++ b/backend/runner/taskrun/executor.go@@ -143,6 +143,7 @@ func getMigrationInfo(ctx context.Context, stores *store.Store, profile config.P// Concat issue title and task name as the migration description so that user can see// more context of the migration.mi.Description = fmt.Sprintf("%s - %s", issue.Title, task.Name)+ mi.ProjectUID = &issue.Project.UIDmi.IssueUID = &issue.UID}diff --git a/backend/store/instance_change_history.go b/backend/store/instance_change_history.goindex ac9c9ea423..df3882e424 100644--- a/backend/store/instance_change_history.go+++ b/backend/store/instance_change_history.go@@ -30,6 +30,7 @@ type InstanceChangeHistoryMessage struct {// nil means bytebase meta instance.InstanceUID *intDatabaseUID *int+ ProjectUID *intIssueUID *intReleaseVersion stringSequence int64@@ -49,13 +50,12 @@ type InstanceChangeHistoryMessage struct {Payload *storepb.InstanceChangeHistoryPayload// Output only- UID string- Deleted bool- Creator *UserMessage- Updater *UserMessage- InstanceID string- DatabaseName string- IssueProjectID string+ UID string+ Deleted bool+ Creator *UserMessage+ Updater *UserMessage+ InstanceID string+ DatabaseName string}// FindInstanceChangeHistoryMessage is for listing a list of instance change history.@@ -109,6 +109,7 @@ func (*Store) createInstanceChangeHistoryImpl(ctx context.Context, tx *Tx, creatupdater_id,instance_id,database_id,+ project_id,issue_id,release_version,sequence,@@ -123,7 +124,7 @@ func (*Store) createInstanceChangeHistoryImpl(ctx context.Context, tx *Tx, creatschema_prev,execution_duration_ns,payload- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)RETURNING id`payload, err := protojson.Marshal(create.Payload)@@ -146,6 +147,7 @@ func (*Store) createInstanceChangeHistoryImpl(ctx context.Context, tx *Tx, creatcreate.CreatorID,create.InstanceUID,create.DatabaseUID,+ create.ProjectUID,create.IssueUID,create.ReleaseVersion,create.Sequence,@@ -174,6 +176,7 @@ func (*Store) createInstanceChangeHistoryImplForMigrator(ctx context.Context, txupdater_id,instance_id,database_id,+ project_id,issue_id,release_version,sequence,@@ -187,7 +190,7 @@ func (*Store) createInstanceChangeHistoryImplForMigrator(ctx context.Context, txschema_prev,execution_duration_ns,payload- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)RETURNING id`payload, err := protojson.Marshal(create.Payload)@@ -205,6 +208,7 @@ func (*Store) createInstanceChangeHistoryImplForMigrator(ctx context.Context, txcreate.CreatorID,create.InstanceUID,create.DatabaseUID,+ create.ProjectUID,create.IssueUID,create.ReleaseVersion,create.Sequence,@@ -518,6 +522,7 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstancinstance_change_history.updated_ts,instance_change_history.instance_id,instance_change_history.database_id,+ instance_change_history.project_id,instance_change_history.issue_id,instance_change_history.release_version,instance_change_history.sequence,@@ -570,7 +575,7 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstancfor rows.Next() {var changeHistory InstanceChangeHistoryMessagevar rowStatus, storedVersion, payload string- var instanceID, databaseID, issueID, sheetID sql.NullInt32+ var instanceID, databaseID, projectID, issueID, sheetID sql.NullInt32if err := rows.Scan(&changeHistory.UID,&rowStatus,@@ -580,6 +585,7 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstanc&changeHistory.UpdatedTs,&instanceID,&databaseID,+ &projectID,&issueID,&changeHistory.ReleaseVersion,&changeHistory.Sequence,@@ -610,6 +616,10 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstancn := int(databaseID.Int32)changeHistory.DatabaseUID = &n}+ if projectID.Valid {+ n := int(projectID.Int32)+ changeHistory.ProjectUID = &n+ }if issueID.Valid {n := int(issueID.Int32)changeHistory.IssueUID = &n@@ -650,13 +660,6 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstancreturn nil, errors.Wrapf(err, "failed to get updater by updaterID %q", changeHistory.UpdaterID)}changeHistory.Updater = updater- if changeHistory.IssueUID != nil {- issue, err := s.GetIssueV2(ctx, &FindIssueMessage{UID: changeHistory.IssueUID})- if err != nil {- return nil, errors.Wrapf(err, "failed to get issue by issueUID %q", *changeHistory.IssueUID)- }- changeHistory.IssueProjectID = issue.Project.ResourceID- }}return list, nil@@ -757,6 +760,7 @@ func (s *Store) CreatePendingInstanceChangeHistory(ctx context.Context, prevScheCreatorID: m.CreatorID,InstanceUID: m.InstanceID,DatabaseUID: m.DatabaseID,+ ProjectUID: m.ProjectUID,IssueUID: m.IssueUID,ReleaseVersion: m.ReleaseVersion,Sequence: nextSequence,@@ -844,6 +848,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *instance_change_history.updated_ts,instance_change_history.instance_id,instance_change_history.database_id,+ instance_change_history.project_id,instance_change_history.issue_id,instance_change_history.release_version,instance_change_history.sequence,@@ -886,7 +891,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *for rows.Next() {var changeHistory InstanceChangeHistoryMessagevar rowStatus, storedVersion, payload string- var instanceID, databaseID, issueID sql.NullInt32+ var instanceID, databaseID, projectID, issueID sql.NullInt32if err := rows.Scan(&changeHistory.UID,&rowStatus,@@ -896,6 +901,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *&changeHistory.UpdatedTs,&instanceID,&databaseID,+ &projectID,&issueID,&changeHistory.ReleaseVersion,&changeHistory.Sequence,@@ -922,6 +928,10 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *n := int(databaseID.Int32)changeHistory.DatabaseUID = &n}+ if projectID.Valid {+ n := int(projectID.Int32)+ changeHistory.ProjectUID = &n+ }if issueID.Valid {n := int(issueID.Int32)changeHistory.IssueUID = &n