Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: migrate sheet storage to SHA256-based content addressing (#18552)
Danny Xubee2080737ed
diff --git a/backend/api/v1/database_service_changelog.go b/backend/api/v1/database_service_changelog.goindex ff75549a41..56262703b4 100644--- a/backend/api/v1/database_service_changelog.go+++ b/backend/api/v1/database_service_changelog.go@@ -140,8 +140,8 @@ func (*DatabaseService) convertToChangelog(d *store.DatabaseMessage, c *store.ChType: changelogType,}- if sheet := c.Payload.GetSheet(); sheet != "" {- cl.StatementSheet = sheet+ if sheetSha256 := c.Payload.GetSheetSha256(); sheetSha256 != "" {+ cl.StatementSheet = common.FormatSheet(d.ProjectID, sheetSha256)cl.Statement = c.Statementcl.StatementSize = c.StatementSize}diff --git a/backend/api/v1/issue_service_converter.go b/backend/api/v1/issue_service_converter.goindex 01c78c48a1..51a0281bc4 100644--- a/backend/api/v1/issue_service_converter.go+++ b/backend/api/v1/issue_service_converter.go@@ -360,7 +360,8 @@ func convertToIssueComment(issueName string, ic *store.IssueCommentMessage) *v1pcase *storepb.IssueCommentPayload_IssueUpdate_:r.Event = convertToIssueCommentEventIssueUpdate(e)case *storepb.IssueCommentPayload_PlanSpecUpdate_:- r.Event = convertToIssueCommentEventPlanSpecUpdate(e)+ projectID, _, _ := common.GetProjectIDIssueUID(issueName)+ r.Event = convertToIssueCommentEventPlanSpecUpdate(projectID, e)}return r@@ -444,12 +445,19 @@ func convertToIssueCommentEventApprovalStatus(s storepb.IssuePayloadApproval_App}}-func convertToIssueCommentEventPlanSpecUpdate(u *storepb.IssueCommentPayload_PlanSpecUpdate_) *v1pb.IssueComment_PlanSpecUpdate_ {- return &v1pb.IssueComment_PlanSpecUpdate_{+func convertToIssueCommentEventPlanSpecUpdate(projectID string, u *storepb.IssueCommentPayload_PlanSpecUpdate_) *v1pb.IssueComment_PlanSpecUpdate_ {+ result := &v1pb.IssueComment_PlanSpecUpdate_{PlanSpecUpdate: &v1pb.IssueComment_PlanSpecUpdate{- Spec: u.PlanSpecUpdate.Spec,- FromSheet: u.PlanSpecUpdate.FromSheet,- ToSheet: u.PlanSpecUpdate.ToSheet,+ Spec: u.PlanSpecUpdate.Spec,},}+ if fromSha256 := u.PlanSpecUpdate.GetFromSheetSha256(); fromSha256 != "" {+ fromSheet := common.FormatSheet(projectID, fromSha256)+ result.PlanSpecUpdate.FromSheet = &fromSheet+ }+ if toSha256 := u.PlanSpecUpdate.GetToSheetSha256(); toSha256 != "" {+ toSheet := common.FormatSheet(projectID, toSha256)+ result.PlanSpecUpdate.ToSheet = &toSheet+ }+ return result}diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.goindex 16b7be8a47..599d3e4682 100644--- a/backend/api/v1/plan_service.go+++ b/backend/api/v1/plan_service.go@@ -401,7 +401,7 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *connect.Request[v}// Compare specs directly- oldSpecs := convertToPlanSpecs(oldPlan.Config.Specs)+ oldSpecs := convertToPlanSpecs(project.ResourceID, oldPlan.Config.Specs)removed, added, updated := diffSpecs(oldSpecs, req.Plan.Specs)// Check if there are any changes at all.@@ -600,35 +600,31 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *connect.Request[v}oldSheetName = config.ChangeDatabaseConfig.Sheet}- sheetProjectID, sheetUID, err := common.GetProjectResourceIDSheetUID(oldSheetName)+ _, newSheetSha256, err := common.GetProjectResourceIDSheetSha256(oldSheetName)if err != nil {- return connect.NewError(connect.CodeInternal, errors.Errorf("failed to get sheet id from %q, error: %v", oldSheetName, err))+ return connect.NewError(connect.CodeInternal, errors.Errorf("failed to get sheet sha256 from %q, error: %v", oldSheetName, err))}- if int(task.Payload.GetSheetId()) == sheetUID {+ if task.Payload.GetSheetSha256() == newSheetSha256 {return nil}- sheet, err := s.store.GetSheetMetadata(ctx, sheetUID)+ _, err = s.store.GetSheetMetadata(ctx, newSheetSha256)if err != nil {return connect.NewError(connect.CodeInternal, errors.Errorf("failed to get sheet %q: %v", oldSheetName, err))}- if sheet.ProjectID != sheetProjectID {- return connect.NewError(connect.CodeNotFound, errors.Errorf("sheet %d not found in project %s", sheetUID, sheetProjectID))- }doUpdate = true- taskPatch.SheetID = &sheet.UID+ taskPatch.SheetSha256 = &newSheetSha256if issue != nil {- oldSheet := common.FormatSheet(issue.Project.ResourceID, int(task.Payload.GetSheetId()))- newSheet := common.FormatSheet(issue.Project.ResourceID, sheet.UID)+ oldSheetSha256 := task.Payload.GetSheetSha256()issueCommentCreates = append(issueCommentCreates, &store.IssueCommentMessage{IssueUID: issue.UID,Payload: &storepb.IssueCommentPayload{Event: &storepb.IssueCommentPayload_PlanSpecUpdate_{PlanSpecUpdate: &storepb.IssueCommentPayload_PlanSpecUpdate{- Spec: common.FormatSpec(issue.Project.ResourceID, oldPlan.UID, specID),- FromSheet: &oldSheet,- ToSheet: &newSheet,+ Spec: common.FormatSpec(issue.Project.ResourceID, oldPlan.UID, specID),+ FromSheetSha256: &oldSheetSha256,+ ToSheetSha256: &newSheetSha256,},},},@@ -688,7 +684,7 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *connect.Request[vvar doUpdateSheet boolfor _, taskPatch := range taskPatchList {- if taskPatch.SheetID != nil {+ if taskPatch.SheetSha256 != nil {doUpdateSheet = true}}diff --git a/backend/api/v1/plan_service_converter.go b/backend/api/v1/plan_service_converter.goindex f0d1b1518e..38df92cbb0 100644--- a/backend/api/v1/plan_service_converter.go+++ b/backend/api/v1/plan_service_converter.go@@ -29,7 +29,7 @@ func convertToPlan(ctx context.Context, s *store.Store, plan *store.PlanMessage)Name: common.FormatPlan(plan.ProjectID, plan.UID),Title: plan.Name,Description: plan.Description,- Specs: convertToPlanSpecs(plan.Config.Specs), // Use specs field for output+ Specs: convertToPlanSpecs(plan.ProjectID, plan.Config.Specs), // Use specs field for outputDeployment: convertToPlanDeployment(plan.Config.Deployment),CreateTime: timestamppb.New(plan.CreatedAt),UpdateTime: timestamppb.New(plan.UpdatedAt),@@ -68,15 +68,15 @@ func convertToPlan(ctx context.Context, s *store.Store, plan *store.PlanMessage)return p, nil}-func convertToPlanSpecs(specs []*storepb.PlanConfig_Spec) []*v1pb.Plan_Spec {+func convertToPlanSpecs(projectID string, specs []*storepb.PlanConfig_Spec) []*v1pb.Plan_Spec {v1Specs := make([]*v1pb.Plan_Spec, len(specs))for i := range specs {- v1Specs[i] = convertToPlanSpec(specs[i])+ v1Specs[i] = convertToPlanSpec(projectID, specs[i])}return v1Specs}-func convertToPlanSpec(spec *storepb.PlanConfig_Spec) *v1pb.Plan_Spec {+func convertToPlanSpec(projectID string, spec *storepb.PlanConfig_Spec) *v1pb.Plan_Spec {v1Spec := &v1pb.Plan_Spec{Id: spec.Id,}@@ -85,9 +85,9 @@ func convertToPlanSpec(spec *storepb.PlanConfig_Spec) *v1pb.Plan_Spec {case *storepb.PlanConfig_Spec_CreateDatabaseConfig:v1Spec.Config = convertToPlanSpecCreateDatabaseConfig(v)case *storepb.PlanConfig_Spec_ChangeDatabaseConfig:- v1Spec.Config = convertToPlanSpecChangeDatabaseConfig(v)+ v1Spec.Config = convertToPlanSpecChangeDatabaseConfig(projectID, v)case *storepb.PlanConfig_Spec_ExportDataConfig:- v1Spec.Config = convertToPlanSpecExportDataConfig(v)+ v1Spec.Config = convertToPlanSpecExportDataConfig(projectID, v)}return v1Spec@@ -109,12 +109,12 @@ func convertToPlanSpecCreateDatabaseConfig(config *storepb.PlanConfig_Spec_Creat}}-func convertToPlanSpecChangeDatabaseConfig(config *storepb.PlanConfig_Spec_ChangeDatabaseConfig) *v1pb.Plan_Spec_ChangeDatabaseConfig {+func convertToPlanSpecChangeDatabaseConfig(projectID string, config *storepb.PlanConfig_Spec_ChangeDatabaseConfig) *v1pb.Plan_Spec_ChangeDatabaseConfig {c := config.ChangeDatabaseConfigreturn &v1pb.Plan_Spec_ChangeDatabaseConfig{ChangeDatabaseConfig: &v1pb.Plan_ChangeDatabaseConfig{Targets: c.Targets,- Sheet: c.Sheet,+ Sheet: common.FormatSheet(projectID, c.SheetSha256),Release: c.Release,Type: convertToPlanSpecChangeDatabaseConfigType(c.Type),GhostFlags: c.GhostFlags,@@ -137,12 +137,12 @@ func convertToPlanSpecChangeDatabaseConfigType(t storepb.PlanConfig_ChangeDataba}}-func convertToPlanSpecExportDataConfig(config *storepb.PlanConfig_Spec_ExportDataConfig) *v1pb.Plan_Spec_ExportDataConfig {+func convertToPlanSpecExportDataConfig(projectID string, config *storepb.PlanConfig_Spec_ExportDataConfig) *v1pb.Plan_Spec_ExportDataConfig {c := config.ExportDataConfigreturn &v1pb.Plan_Spec_ExportDataConfig{ExportDataConfig: &v1pb.Plan_ExportDataConfig{Targets: c.Targets,- Sheet: c.Sheet,+ Sheet: common.FormatSheet(projectID, c.SheetSha256),Format: convertExportFormat(c.Format),Password: c.Password,},@@ -248,10 +248,20 @@ func convertPlanSpecChangeDatabaseConfig(config *v1pb.Plan_Spec_ChangeDatabaseCostoreType = storepb.PlanConfig_ChangeDatabaseConfig_TYPE_UNSPECIFIED}+ // Sheet can be empty when using Release-based workflow (SQL comes from release files).+ // Plans can use either Sheet-based or Release-based approach, but not both.+ var sheetSha256 string+ if c.Sheet != "" {+ _, sha256, err := common.GetProjectResourceIDSheetSha256(c.Sheet)+ if err != nil {+ return nil+ }+ sheetSha256 = sha256+ }return &storepb.PlanConfig_Spec_ChangeDatabaseConfig{ChangeDatabaseConfig: &storepb.PlanConfig_ChangeDatabaseConfig{Targets: c.Targets,- Sheet: c.Sheet,+ SheetSha256: sheetSha256,Release: c.Release,Type: storeType,GhostFlags: c.GhostFlags,@@ -263,12 +273,21 @@ func convertPlanSpecChangeDatabaseConfig(config *v1pb.Plan_Spec_ChangeDatabaseCofunc convertPlanSpecExportDataConfig(config *v1pb.Plan_Spec_ExportDataConfig) *storepb.PlanConfig_Spec_ExportDataConfig {c := config.ExportDataConfig+ // Sheet can be empty if not yet attached to the export data config.+ var sheetSha256 string+ if c.Sheet != "" {+ _, sha256, err := common.GetProjectResourceIDSheetSha256(c.Sheet)+ if err != nil {+ return nil+ }+ sheetSha256 = sha256+ }return &storepb.PlanConfig_Spec_ExportDataConfig{ExportDataConfig: &storepb.PlanConfig_ExportDataConfig{- Targets: c.Targets,- Sheet: c.Sheet,- Format: convertToExportFormat(c.Format),- Password: c.Password,+ Targets: c.Targets,+ SheetSha256: sheetSha256,+ Format: convertToExportFormat(c.Format),+ Password: c.Password,},}}@@ -297,15 +316,13 @@ func convertToPlanCheckRun(ctx context.Context, s *store.Store, projectID stringError: run.Result.Error,}- if sheetUID := int(run.Config.GetSheetUid()); sheetUID != 0 {- sheet, err := s.GetSheetMetadata(ctx, sheetUID)+ if sheetSha256 := run.Config.GetSheetSha256(); sheetSha256 != "" {+ _, err := s.GetSheetMetadata(ctx, sheetSha256)if err != nil {return nil, errors.Wrapf(err, "failed to get sheet")}- if sheet.ProjectID != projectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, projectID)- }- converted.Sheet = common.FormatSheet(projectID, sheet.UID)+ // Sheets are now project-agnostic, no need to check projectID+ converted.Sheet = common.FormatSheet(projectID, sheetSha256)}return converted, nildiff --git a/backend/api/v1/plan_service_plan_check.go b/backend/api/v1/plan_service_plan_check.goindex 28b07bacbb..a99724f2ce 100644--- a/backend/api/v1/plan_service_plan_check.go+++ b/backend/api/v1/plan_service_plan_check.go@@ -54,7 +54,7 @@ func getPlanCheckRunsFromPlanSpecs(ctx context.Context, s *store.Store, plan *stvar updatedRuns []*store.PlanCheckRunMessagecountMap := make(map[string]int32)for _, run := range planCheckRuns {- key := fmt.Sprintf("%s/%d", run.Type, run.Config.GetSheetUid())+ key := fmt.Sprintf("%s/%s", run.Type, run.Config.GetSheetSha256())if countMap[key] >= project.Setting.GetCiSamplingSize() {continue}@@ -113,22 +113,19 @@ func getPlanCheckRunsFromChangeDatabaseConfigDatabaseGroupTarget(ctx context.Conreturn nil, errors.Errorf("no matched databases found in database group %q", target)}- sheetUIDs, err := getSheetUIDsFromChangeDatabaseConfig(config)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheets from change database config")- }- if len(sheetUIDs) == 0 {+ sheetSha256s := getSheetSha256sFromChangeDatabaseConfig(config)+ if len(sheetSha256s) == 0 {return nil, errors.Errorf("change database config must have sheet specified, but got none")}var planCheckRuns []*store.PlanCheckRunMessagefor _, matchedDatabase := range databaseGroup.MatchedDatabases {- for _, sheetUID := range sheetUIDs {+ for _, sheetSha256 := range sheetSha256s {database, err := getDatabaseMessage(ctx, s, matchedDatabase.Name)if err != nil {return nil, err}- runs, err := getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx, s, plan, config, sheetUID, database)+ runs, err := getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx, s, plan, config, sheetSha256, database)if err != nil {return nil, errors.Wrapf(err, "failed to get plan check runs from spec with change database config for database %q", database.DatabaseName)}@@ -140,11 +137,8 @@ func getPlanCheckRunsFromChangeDatabaseConfigDatabaseGroupTarget(ctx context.Con}func getPlanCheckRunsFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s *store.Store, plan *store.PlanMessage, config *storepb.PlanConfig_ChangeDatabaseConfig) ([]*store.PlanCheckRunMessage, error) {- sheetUIDs, err := getSheetUIDsFromChangeDatabaseConfig(config)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheets from change database config")- }- if len(sheetUIDs) == 0 {+ sheetSha256s := getSheetSha256sFromChangeDatabaseConfig(config)+ if len(sheetSha256s) == 0 {return nil, errors.Errorf("change database config must have sheet specified, but got none")}@@ -157,8 +151,8 @@ func getPlanCheckRunsFromChangeDatabaseConfigDatabaseTarget(ctx context.Context,if database.Deleted {return nil, errors.Errorf("database %q was deleted", target)}- for _, sheetUID := range sheetUIDs {- v, err := getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx, s, plan, config, sheetUID, database)+ for _, sheetSha256 := range sheetSha256s {+ v, err := getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx, s, plan, config, sheetSha256, database)if err != nil {return nil, err}@@ -168,7 +162,7 @@ func getPlanCheckRunsFromChangeDatabaseConfigDatabaseTarget(ctx context.Context,return checks, nil}-func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, s *store.Store, plan *store.PlanMessage, config *storepb.PlanConfig_ChangeDatabaseConfig, sheetUID int, database *store.DatabaseMessage) ([]*store.PlanCheckRunMessage, error) {+func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, s *store.Store, plan *store.PlanMessage, config *storepb.PlanConfig_ChangeDatabaseConfig, sheetSha256 string, database *store.DatabaseMessage) ([]*store.PlanCheckRunMessage, error) {instance, err := s.GetInstance(ctx, &store.FindInstanceMessage{ResourceID: &database.InstanceID,})@@ -178,13 +172,11 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sif instance == nil {return nil, errors.Errorf("instance %q not found", database.InstanceID)}- sheet, err := s.GetSheetMetadata(ctx, sheetUID)+ _, err = s.GetSheetMetadata(ctx, sheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %d", sheetUID)- }- if sheet.ProjectID != plan.ProjectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, plan.ProjectID)+ return nil, errors.Wrapf(err, "failed to get sheet %s", sheetSha256)}+ // Sheets are now project-agnostic, no need to check projectIDenableSDL := config.Type == storepb.PlanConfig_ChangeDatabaseConfig_SDL@@ -194,7 +186,7 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sStatus: store.PlanCheckRunStatusRunning,Type: store.PlanCheckDatabaseConnect,Config: &storepb.PlanCheckRunConfig{- SheetUid: int32(sheetUID),+ SheetSha256: sheetSha256,InstanceId: instance.ResourceID,DatabaseName: database.DatabaseName,EnableGhost: config.EnableGhost,@@ -207,7 +199,7 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sStatus: store.PlanCheckRunStatusRunning,Type: store.PlanCheckDatabaseStatementAdvise,Config: &storepb.PlanCheckRunConfig{- SheetUid: int32(sheetUID),+ SheetSha256: sheetSha256,InstanceId: instance.ResourceID,DatabaseName: database.DatabaseName,EnablePriorBackup: config.EnablePriorBackup,@@ -220,7 +212,7 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sStatus: store.PlanCheckRunStatusRunning,Type: store.PlanCheckDatabaseStatementSummaryReport,Config: &storepb.PlanCheckRunConfig{- SheetUid: int32(sheetUID),+ SheetSha256: sheetSha256,InstanceId: instance.ResourceID,DatabaseName: database.DatabaseName,EnableGhost: config.EnableGhost,@@ -233,7 +225,7 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sStatus: store.PlanCheckRunStatusRunning,Type: store.PlanCheckDatabaseGhostSync,Config: &storepb.PlanCheckRunConfig{- SheetUid: int32(sheetUID),+ SheetSha256: sheetSha256,InstanceId: instance.ResourceID,DatabaseName: database.DatabaseName,EnableGhost: config.EnableGhost,@@ -246,14 +238,10 @@ func getPlanCheckRunsFromChangeDatabaseConfigForDatabase(ctx context.Context, sreturn planCheckRuns, nil}-func getSheetUIDsFromChangeDatabaseConfig(config *storepb.PlanConfig_ChangeDatabaseConfig) ([]int, error) {- var sheetUIDs []int- if config.Sheet != "" {- _, sheetUID, err := common.GetProjectResourceIDSheetUID(config.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet name %q", config.Sheet)- }- sheetUIDs = append(sheetUIDs, sheetUID)+func getSheetSha256sFromChangeDatabaseConfig(config *storepb.PlanConfig_ChangeDatabaseConfig) []string {+ var sheetSha256s []string+ if config.SheetSha256 != "" {+ sheetSha256s = append(sheetSha256s, config.SheetSha256)}- return sheetUIDs, nil+ return sheetSha256s}diff --git a/backend/api/v1/release_service.go b/backend/api/v1/release_service.goindex 0d4eb20dd5..eb98fa9d8f 100644--- a/backend/api/v1/release_service.go+++ b/backend/api/v1/release_service.go@@ -4,7 +4,6 @@ import ("context""crypto/sha256""encoding/hex"- "fmt""slices""connectrpc.com/connect"@@ -84,7 +83,6 @@ func (s *ReleaseService) CreateRelease(ctx context.Context, req *connect.Requestif file.Sheet == "" {// statement must be present due to validation in validateAndSanitizeReleaseFilessheet := &store.SheetMessage{- Title: fmt.Sprintf("File %s", file.Path),Statement: string(file.Statement),}sheetsToCreate = append(sheetsToCreate, sheet)@@ -94,7 +92,7 @@ func (s *ReleaseService) CreateRelease(ctx context.Context, req *connect.Request// Batch create sheets if needed.if len(sheetsToCreate) > 0 {- createdSheets, err := s.store.CreateSheets(ctx, project.ResourceID, user.Email, sheetsToCreate...)+ createdSheets, err := s.store.CreateSheets(ctx, sheetsToCreate...)if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to create sheets"))}@@ -104,7 +102,7 @@ func (s *ReleaseService) CreateRelease(ctx context.Context, req *connect.Request// Map created sheets back to files.for i, sheet := range createdSheets {- filesWithoutSheet[i].Sheet = common.FormatSheet(project.ResourceID, sheet.UID)+ filesWithoutSheet[i].Sheet = common.FormatSheet(project.ResourceID, sheet.Sha256)}}@@ -118,23 +116,20 @@ func (s *ReleaseService) CreateRelease(ctx context.Context, req *connect.Request}for _, f := range sanitizedFiles {- projectID, sheetUID, err := common.GetProjectResourceIDSheetUID(f.Sheet)+ _, sheetSha256, err := common.GetProjectResourceIDSheetSha256(f.Sheet)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheetUID from %q", f.Sheet)+ return nil, errors.Wrapf(err, "failed to get sheetSha256 from %q", f.Sheet)}- sheet, err := s.store.GetSheetMetadata(ctx, sheetUID)+ _, err = s.store.GetSheetMetadata(ctx, sheetSha256)if err != nil {return nil, errors.Wrapf(err, "failed to get sheet %q", f.Sheet)}- if sheet.ProjectID != projectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, projectID)- }+ // Sheets are now project-agnostic, no need to check projectIDreleaseMessage.Payload.Files = append(releaseMessage.Payload.Files, &storepb.ReleasePayload_File{Id: f.Id,Path: f.Path,- Sheet: f.Sheet,- SheetSha256: sheet.GetSha256Hex(),+ SheetSha256: sheetSha256,Type: storepb.SchemaChangeType(f.Type),Version: f.Version,EnableGhost: f.EnableGhost,@@ -436,21 +431,15 @@ func convertToRelease(ctx context.Context, s *store.Store, release *store.Releas}for _, f := range release.Payload.Files {- projectID, sheetUID, err := common.GetProjectResourceIDSheetUID(f.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheetUID from %q", f.Sheet)- }- sheet, err := s.GetSheetMetadata(ctx, sheetUID)+ sheet, err := s.GetSheetMetadata(ctx, f.SheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %q", f.Sheet)- }- if sheet.ProjectID != projectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, projectID)+ return nil, errors.Wrapf(err, "failed to get sheet with sha256 %q", f.SheetSha256)}+ // Sheets are now project-agnostic, no need to check projectIDr.Files = append(r.Files, &v1pb.Release_File{Id: f.Id,Path: f.Path,- Sheet: f.Sheet,+ Sheet: common.FormatSheet(release.ProjectID, f.SheetSha256),SheetSha256: f.SheetSha256,Type: v1pb.Release_File_Type(f.Type),Version: f.Version,@@ -510,19 +499,17 @@ func validateAndSanitizeReleaseFiles(ctx context.Context, s *store.Store, files// If sheet is provided but statement is not, populate statement from sheetcase f.Sheet != "":- projectID, sheetUID, err := common.GetProjectResourceIDSheetUID(f.Sheet)+ _, sheetSha256, err := common.GetProjectResourceIDSheetSha256(f.Sheet)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet UID from %q", f.Sheet)+ return nil, errors.Wrapf(err, "failed to get sheet SHA256 from %q", f.Sheet)}- sheet, err := s.GetSheetFull(ctx, sheetUID)+ sheet, err := s.GetSheetFull(ctx, sheetSha256)if err != nil {return nil, errors.Wrapf(err, "failed to get sheet %q", f.Sheet)}- if sheet.ProjectID != projectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, projectID)- }+ // Sheets are now project-agnostic, no need to check projectIDf.Statement = []byte(sheet.Statement)- f.SheetSha256 = sheet.GetSha256Hex()+ f.SheetSha256 = sheet.Sha256case len(f.Statement) > 0:// populate sheetSha256 from statementh := sha256.Sum256(f.Statement)diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.goindex 66417d1909..4359b8cc62 100644--- a/backend/api/v1/release_service_check.go+++ b/backend/api/v1/release_service_check.go@@ -444,9 +444,9 @@ func (s *ReleaseService) checkReleaseDeclarative(ctx context.Context, files []*vvar previousUserSDL stringif len(revisions) > 0 {// Get sheet statement from revision- _, sheetUID, err := common.GetProjectResourceIDSheetUID(revisions[0].Payload.Sheet)- if err == nil {- if sheet, err := s.store.GetSheetFull(ctx, sheetUID); err == nil {+ sheetSha256 := revisions[0].Payload.SheetSha256+ if sheetSha256 != "" {+ if sheet, err := s.store.GetSheetFull(ctx, sheetSha256); err == nil {previousUserSDL = sheet.Statement}}diff --git a/backend/api/v1/revision_service.go b/backend/api/v1/revision_service.goindex d39ab49645..3d32f7f88f 100644--- a/backend/api/v1/revision_service.go+++ b/backend/api/v1/revision_service.go@@ -127,17 +127,14 @@ func (s *RevisionService) CreateRevision(if database == nil || database.Deleted {return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("database %v not found", request.Parent))}- sheetProjectID, sheetUID, err := common.GetProjectResourceIDSheetUID(request.Revision.Sheet)+ _, sheetSha256, err := common.GetProjectResourceIDSheetSha256(request.Revision.Sheet)if err != nil {return nil, connect.NewError(connect.CodeInvalidArgument, errors.Wrapf(err, "failed to get sheet from %v", request.Revision.Sheet))}- sheet, err := s.store.GetSheetMetadata(ctx, sheetUID)+ sheet, err := s.store.GetSheetMetadata(ctx, sheetSha256)if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get sheet"))}- if sheet.ProjectID != sheetProjectID {- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("sheet %d not found in project %s", sheetUID, sheetProjectID))- }if request.Revision.TaskRun != "" {projectID, rolloutID, stageID, taskID, taskRunID, err := common.GetProjectIDRolloutIDStageIDTaskIDTaskRunID(request.Revision.TaskRun)@@ -185,8 +182,9 @@ func (s *RevisionService) CreateRevision(for _, f := range release.Payload.Files {if f.Id == fileID {foundFile = true- if f.Sheet != request.Revision.Sheet {- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("The sheet in file %q is %q which is different from revision.sheet %q", fileID, f.Sheet, request.Revision.Sheet))+ fileSheet := common.FormatSheet(release.ProjectID, f.SheetSha256)+ if fileSheet != request.Revision.Sheet {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("The sheet in file %q is %q which is different from revision.sheet %q", fileID, fileSheet, request.Revision.Sheet))}break}@@ -274,16 +272,21 @@ func convertToRevisions(ctx context.Context, s *store.Store, parent string, revi}func convertToRevision(ctx context.Context, s *store.Store, parent string, revision *store.RevisionMessage) (*v1pb.Revision, error) {- sheetProjectID, sheetUID, err := common.GetProjectResourceIDSheetUID(revision.Payload.Sheet)+ sheetSha256 := revision.Payload.SheetSha256+ sheet, err := s.GetSheetMetadata(ctx, sheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheetUID from %q", revision.Payload.Sheet)+ return nil, errors.Wrapf(err, "failed to get sheet %q", sheetSha256)}- sheet, err := s.GetSheetMetadata(ctx, sheetUID)++ database, err := s.GetDatabase(ctx, &store.FindDatabaseMessage{+ InstanceID: &revision.InstanceID,+ DatabaseName: &revision.DatabaseName,+ })if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %q", revision.Payload.Sheet)+ return nil, errors.Wrapf(err, "failed to get database")}- if sheet.ProjectID != sheetProjectID {- return nil, errors.Errorf("sheet %d not in project %s", sheetUID, sheetProjectID)+ if database == nil {+ return nil, errors.Errorf("database not found")}taskRunName := revision.Payload.TaskRun@@ -291,7 +294,7 @@ func convertToRevision(ctx context.Context, s *store.Store, parent string, revisName: fmt.Sprintf("%s/%s%d", parent, common.RevisionNamePrefix, revision.UID),Release: revision.Payload.Release,CreateTime: timestamppb.New(revision.CreatedAt),- Sheet: revision.Payload.Sheet,+ Sheet: common.FormatSheet(database.ProjectID, sheetSha256),SheetSha256: revision.Payload.SheetSha256,Statement: sheet.Statement,StatementSize: sheet.Size,@@ -333,8 +336,7 @@ func convertRevision(revision *v1pb.Revision, database *store.DatabaseMessage, sPayload: &storepb.RevisionPayload{Release: revision.Release,File: revision.File,- Sheet: revision.Sheet,- SheetSha256: sheet.GetSha256Hex(),+ SheetSha256: sheet.Sha256,TaskRun: revision.TaskRun,Type: convertRevisionType(revision.Type),},diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.goindex 8ee6a84d6a..79cc27113d 100644--- a/backend/api/v1/rollout_service.go+++ b/backend/api/v1/rollout_service.go@@ -614,9 +614,9 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, req *connect.Requestcreate := &store.TaskRunMessage{TaskUID: task.ID,}- if task.Payload.GetSheetId() != 0 {- sheetUID := int(task.Payload.GetSheetId())- create.SheetUID = &sheetUID+ if task.Payload.GetSheetSha256() != "" {+ sheetSha256 := task.Payload.GetSheetSha256()+ create.SheetSha256 = &sheetSha256}if request.GetRunTime() != nil {t := request.GetRunTime().AsTime()@@ -910,10 +910,10 @@ func (s *RolloutService) PreviewTaskRunRollback(ctx context.Context, req *connecreturn nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get instance, error: %v", err))}- if taskRun.SheetUID == nil {+ if taskRun.SheetSha256 == nil {return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("task run %v has no sheet", taskRun.ID))}- sheet, err := s.store.GetSheetFull(ctx, *taskRun.SheetUID)+ sheet, err := s.store.GetSheetFull(ctx, *taskRun.SheetSha256)if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get sheet statements, error: %v", err))}@@ -973,7 +973,7 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, dbFactory *dbfactory// Step 2 - convert all task creates.var taskCreates []*store.TaskMessagefor _, spec := range transformedSpecs {- tcs, err := getTaskCreatesFromSpec(ctx, s, dbFactory, spec, project)+ tcs, err := getTaskCreatesFromSpec(ctx, s, dbFactory, spec)if err != nil {return nil, errors.Wrap(err, "failed to get task creates from spec")}diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.goindex 315f3b85de..dd8ce8c51a 100644--- a/backend/api/v1/rollout_service_converter.go+++ b/backend/api/v1/rollout_service_converter.go@@ -55,8 +55,8 @@ func convertToTaskRun(ctx context.Context, s *store.Store, stateCfg *state.Statet.RunTime = timestamppb.New(*taskRun.RunAt)}- if taskRun.SheetUID != nil && *taskRun.SheetUID != 0 {- t.Sheet = common.FormatSheet(taskRun.ProjectID, *taskRun.SheetUID)+ if taskRun.SheetSha256 != nil && *taskRun.SheetSha256 != "" {+ t.Sheet = common.FormatSheet(taskRun.ProjectID, *taskRun.SheetSha256)}if v, ok := stateCfg.TaskRunSchedulerInfo.Load(taskRun.ID); ok {@@ -323,7 +323,7 @@ func convertToTaskFromDatabaseCreate(ctx context.Context, s *store.Store, projecProject: "",Database: task.Payload.GetDatabaseName(),Table: task.Payload.GetTableName(),- Sheet: common.FormatSheet(project.ResourceID, int(task.Payload.GetSheetId())),+ Sheet: common.FormatSheet(project.ResourceID, task.Payload.GetSheetSha256()),CharacterSet: task.Payload.GetCharacterSet(),Collation: task.Payload.GetCollation(),Environment: common.FormatEnvironment(task.Payload.GetEnvironmentId()),@@ -372,7 +372,7 @@ func convertToTaskFromSchemaUpdate(ctx context.Context, s *store.Store, projectTarget: fmt.Sprintf("%s%s/%s%s", common.InstanceNamePrefix, database.InstanceID, common.DatabaseIDPrefix, database.DatabaseName),Payload: &v1pb.Task_DatabaseUpdate_{DatabaseUpdate: &v1pb.Task_DatabaseUpdate{- Sheet: common.FormatSheet(project.ResourceID, int(task.Payload.GetSheetId())),+ Sheet: common.FormatSheet(project.ResourceID, task.Payload.GetSheetSha256()),SchemaVersion: task.Payload.GetSchemaVersion(),DatabaseChangeType: databaseChangeType,},@@ -399,7 +399,7 @@ func convertToTaskFromDatabaseDataExport(ctx context.Context, s *store.Store, prreturn nil, errors.Errorf("database not found")}targetDatabaseName := fmt.Sprintf("%s%s/%s%s", common.InstanceNamePrefix, database.InstanceID, common.DatabaseIDPrefix, database.DatabaseName)- sheet := common.FormatSheet(project.ResourceID, int(task.Payload.GetSheetId()))+ sheet := common.FormatSheet(project.ResourceID, task.Payload.GetSheetSha256())v1pbTaskPayload := v1pb.Task_DatabaseDataExport_{DatabaseDataExport: &v1pb.Task_DatabaseDataExport{Target: targetDatabaseName,diff --git a/backend/api/v1/rollout_service_task.go b/backend/api/v1/rollout_service_task.goindex 1bd08dc568..e82e4481e0 100644--- a/backend/api/v1/rollout_service_task.go+++ b/backend/api/v1/rollout_service_task.go@@ -46,10 +46,10 @@ func applyDatabaseGroupSpecTransformations(specs []*storepb.PlanConfig_Spec, depreturn result}-func getTaskCreatesFromSpec(ctx context.Context, s *store.Store, dbFactory *dbfactory.DBFactory, spec *storepb.PlanConfig_Spec, project *store.ProjectMessage) ([]*store.TaskMessage, error) {+func getTaskCreatesFromSpec(ctx context.Context, s *store.Store, dbFactory *dbfactory.DBFactory, spec *storepb.PlanConfig_Spec) ([]*store.TaskMessage, error) {switch config := spec.Config.(type) {case *storepb.PlanConfig_Spec_CreateDatabaseConfig:- return getTaskCreatesFromCreateDatabaseConfig(ctx, s, dbFactory, spec, config.CreateDatabaseConfig, project)+ return getTaskCreatesFromCreateDatabaseConfig(ctx, s, dbFactory, spec, config.CreateDatabaseConfig)case *storepb.PlanConfig_Spec_ChangeDatabaseConfig:return getTaskCreatesFromChangeDatabaseConfig(ctx, s, spec, config.ChangeDatabaseConfig)case *storepb.PlanConfig_Spec_ExportDataConfig:@@ -59,7 +59,7 @@ func getTaskCreatesFromSpec(ctx context.Context, s *store.Store, dbFactory *dbfareturn nil, errors.Errorf("invalid spec config type %T", spec.Config)}-func getTaskCreatesFromCreateDatabaseConfig(ctx context.Context, s *store.Store, dbFactory *dbfactory.DBFactory, spec *storepb.PlanConfig_Spec, c *storepb.PlanConfig_CreateDatabaseConfig, project *store.ProjectMessage) ([]*store.TaskMessage, error) {+func getTaskCreatesFromCreateDatabaseConfig(ctx context.Context, s *store.Store, dbFactory *dbfactory.DBFactory, spec *storepb.PlanConfig_Spec, c *storepb.PlanConfig_CreateDatabaseConfig) ([]*store.TaskMessage, error) {if c.Database == "" {return nil, errors.Errorf("database name is required")}@@ -141,8 +141,7 @@ func getTaskCreatesFromCreateDatabaseConfig(ctx context.Context, s *store.Store,if err != nil {return nil, err}- sheets, err := s.CreateSheets(ctx, project.ResourceID, common.SystemBotEmail, &store.SheetMessage{- Title: fmt.Sprintf("Sheet for creating database %v", databaseName),+ sheets, err := s.CreateSheets(ctx, &store.SheetMessage{Statement: statement,})if err != nil {@@ -162,7 +161,7 @@ func getTaskCreatesFromCreateDatabaseConfig(ctx context.Context, s *store.Store,Collation: c.Collation,EnvironmentId: dbEnvironmentID,DatabaseName: databaseName,- SheetId: int32(sheet.UID),+ SheetSha256: sheet.Sha256,},}return []*store.TaskMessage{@@ -250,14 +249,10 @@ func getTaskCreatesFromExportDataConfig(return nil, err}- _, sheetUID, err := common.GetProjectResourceIDSheetUID(c.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet %q", c.Sheet)- }payload := &storepb.Task{- SpecId: spec.Id,- SheetId: int32(sheetUID),- Format: c.Format,+ SpecId: spec.Id,+ SheetSha256: c.SheetSha256,+ Format: c.Format,}if c.Password != nil {payload.Password = *c.Password@@ -287,10 +282,6 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget() ([]*store.TaskMessage, error) {switch c.Type {case storepb.PlanConfig_ChangeDatabaseConfig_MIGRATE:- _, sheetUID, err := common.GetProjectResourceIDSheetUID(c.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet %q", c.Sheet)- }env := ""if database.EffectiveEnvironmentID != nil {env = *database.EffectiveEnvironmentID@@ -312,7 +303,7 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(Type: storepb.Task_DATABASE_MIGRATE,Payload: &storepb.Task{SpecId: spec.Id,- SheetId: int32(sheetUID),+ SheetSha256: c.SheetSha256,Flags: flags,EnablePriorBackup: c.EnablePriorBackup,EnableGhost: c.EnableGhost,@@ -321,10 +312,6 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(return []*store.TaskMessage{taskCreate}, nilcase storepb.PlanConfig_ChangeDatabaseConfig_SDL:- _, sheetUID, err := common.GetProjectResourceIDSheetUID(c.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet %q", c.Sheet)- }env := ""if database.EffectiveEnvironmentID != nil {env = *database.EffectiveEnvironmentID@@ -335,8 +322,8 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(Environment: env,Type: storepb.Task_DATABASE_SDL,Payload: &storepb.Task{- SpecId: spec.Id,- SheetId: int32(sheetUID),+ SpecId: spec.Id,+ SheetSha256: c.SheetSha256,},}return []*store.TaskMessage{taskCreate}, nil@@ -411,16 +398,10 @@ func getTaskCreatesFromChangeDatabaseConfigWithRelease(continue}- // Parse sheet ID from the file's sheet reference- _, sheetUID, err := common.GetProjectResourceIDSheetUID(file.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet %q in release file %q", file.Sheet, file.Id)- }-// Create task payloadpayload := &storepb.Task{SpecId: spec.Id,- SheetId: int32(sheetUID),+ SheetSha256: file.SheetSha256,SchemaVersion: file.Version,EnableGhost: file.EnableGhost,TaskReleaseSource: &storepb.TaskReleaseSource{@@ -455,14 +436,9 @@ func getTaskCreatesFromChangeDatabaseConfigWithRelease(continue}- // Parse sheet ID from the file's sheet reference- _, sheetUID, err := common.GetProjectResourceIDSheetUID(file.Sheet)- if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet id from sheet %q in release file %q", file.Sheet, file.Id)- }payload := &storepb.Task{SpecId: spec.Id,- SheetId: int32(sheetUID),+ SheetSha256: file.SheetSha256,SchemaVersion: file.Version,TaskReleaseSource: &storepb.TaskReleaseSource{File: common.FormatReleaseFile(c.Release, file.Id),diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.goindex f7528aceb9..f57eb9cb25 100644--- a/backend/api/v1/sheet_service.go+++ b/backend/api/v1/sheet_service.go@@ -42,10 +42,6 @@ func (s *SheetService) CreateSheet(ctx context.Context, request *connect.Requestif request.Msg.Sheet == nil {return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("sheet must be set"))}- user, ok := GetUserFromContext(ctx)- if !ok {- return nil, connect.NewError(connect.CodeInternal, errors.Errorf("user not found"))- }projectResourceID, err := common.GetProjectID(request.Msg.Parent)if err != nil {@@ -64,13 +60,13 @@ func (s *SheetService) CreateSheet(ctx context.Context, request *connect.Requestreturn nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with resource id %q had deleted", projectResourceID))}- storeSheetCreate := convertToStoreSheetMessage(project.ResourceID, user.Email, request.Msg.Sheet)- sheets, err := s.store.CreateSheets(ctx, project.ResourceID, user.Email, storeSheetCreate)+ storeSheetCreate := convertToStoreSheetMessage(request.Msg.Sheet)+ sheets, err := s.store.CreateSheets(ctx, storeSheetCreate)if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to create sheet"))}sheet := sheets[0]- v1pbSheet, err := s.convertToAPISheetMessage(ctx, sheet)+ v1pbSheet, err := s.convertToAPISheetMessage(ctx, project.ResourceID, sheet)if err != nil {return nil, err}@@ -81,10 +77,6 @@ func (s *SheetService) BatchCreateSheets(ctx context.Context, request *connect.Rif len(request.Msg.Requests) == 0 {return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("requests must be set"))}- user, ok := GetUserFromContext(ctx)- if !ok {- return nil, connect.NewError(connect.CodeInternal, errors.Errorf("user not found"))- }projectResourceID, err := common.GetProjectID(request.Msg.Parent)if err != nil {@@ -109,18 +101,18 @@ func (s *SheetService) BatchCreateSheets(ctx context.Context, request *connect.Rreturn nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("Sheet Parent %q does not match BatchCreateSheetsRequest.Parent %q", r.Parent, request.Msg.Parent))}- storeSheetCreate := convertToStoreSheetMessage(project.ResourceID, user.Email, r.Sheet)+ storeSheetCreate := convertToStoreSheetMessage(r.Sheet)sheetCreates = append(sheetCreates, storeSheetCreate)}- sheets, err := s.store.CreateSheets(ctx, project.ResourceID, user.Email, sheetCreates...)+ sheets, err := s.store.CreateSheets(ctx, sheetCreates...)if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to create sheet"))}response := &v1pb.BatchCreateSheetsResponse{}for _, sheet := range sheets {- v1pbSheet, err := s.convertToAPISheetMessage(ctx, sheet)+ v1pbSheet, err := s.convertToAPISheetMessage(ctx, project.ResourceID, sheet)if err != nil {return nil, err}@@ -131,12 +123,12 @@ func (s *SheetService) BatchCreateSheets(ctx context.Context, request *connect.R// GetSheet returns the requested sheet, cutoff the content if the content is too long and the `raw` flag in request is false.func (s *SheetService) GetSheet(ctx context.Context, request *connect.Request[v1pb.GetSheetRequest]) (*connect.Response[v1pb.Sheet], error) {- projectResourceID, sheetUID, err := common.GetProjectResourceIDSheetUID(request.Msg.Name)+ projectResourceID, sheetSha256, err := common.GetProjectResourceIDSheetSha256(request.Msg.Name)if err != nil {return nil, connect.NewError(connect.CodeInvalidArgument, err)}- if sheetUID <= 0 {- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid sheet id %d, must be positive integer", sheetUID))+ if sheetSha256 == "" {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid sheet sha256, must be non-empty"))}project, err := s.store.GetProject(ctx, &store.FindProjectMessage{@@ -155,9 +147,9 @@ func (s *SheetService) GetSheet(ctx context.Context, request *connect.Request[v1var sheet *store.SheetMessagevar sheetErr errorif request.Msg.Raw {- sheet, sheetErr = s.store.GetSheetFull(ctx, sheetUID)+ sheet, sheetErr = s.store.GetSheetFull(ctx, sheetSha256)} else {- sheet, sheetErr = s.store.GetSheetMetadata(ctx, sheetUID)+ sheet, sheetErr = s.store.GetSheetMetadata(ctx, sheetSha256)}if sheetErr != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(sheetErr, "failed to get sheet"))@@ -165,40 +157,34 @@ func (s *SheetService) GetSheet(ctx context.Context, request *connect.Request[v1if sheet == nil {return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("cannot find the sheet"))}- // Verify project matches- if sheet.ProjectID != project.ResourceID {- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("sheet not found in project"))- }- v1pbSheet, err := s.convertToAPISheetMessage(ctx, sheet)+ v1pbSheet, err := s.convertToAPISheetMessage(ctx, project.ResourceID, sheet)if err != nil {return nil, err}return connect.NewResponse(v1pbSheet), nil}-func (s *SheetService) convertToAPISheetMessage(ctx context.Context, sheet *store.SheetMessage) (*v1pb.Sheet, error) {+func (s *SheetService) convertToAPISheetMessage(ctx context.Context, projectID string, sheet *store.SheetMessage) (*v1pb.Sheet, error) {project, err := s.store.GetProject(ctx, &store.FindProjectMessage{- ResourceID: &sheet.ProjectID,+ ResourceID: &projectID,})if err != nil {return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get project"))}if project == nil {- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with id %s not found", sheet.ProjectID))+ return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with id %s not found", projectID))}return &v1pb.Sheet{- Name: common.FormatSheet(project.ResourceID, sheet.UID),+ Name: common.FormatSheet(project.ResourceID, sheet.Sha256),Content: []byte(sheet.Statement),ContentSize: sheet.Size,}, nil}-func convertToStoreSheetMessage(projectID string, creator string, sheet *v1pb.Sheet) *store.SheetMessage {+func convertToStoreSheetMessage(sheet *v1pb.Sheet) *store.SheetMessage {sheetMessage := &store.SheetMessage{- ProjectID: projectID,- Creator: creator,Statement: string(sheet.Content),}diff --git a/backend/common/resource_name.go b/backend/common/resource_name.goindex 5b5003dcc7..274e9980a7 100644--- a/backend/common/resource_name.go+++ b/backend/common/resource_name.go@@ -373,17 +373,13 @@ func GetRoleID(name string) (string, error) {return tokens[0], nil}-// GetProjectResourceIDSheetUID returns the project ID and sheet UID from a resource name.-func GetProjectResourceIDSheetUID(name string) (string, int, error) {+// GetProjectResourceIDSheetSha256 returns the project ID and sheet SHA256 from a resource name.+func GetProjectResourceIDSheetSha256(name string) (string, string, error) {tokens, err := GetNameParentTokens(name, ProjectNamePrefix, SheetIDPrefix)if err != nil {- return "", 0, err- }- sheetUID, err := strconv.Atoi(tokens[1])- if err != nil {- return "", 0, errors.Wrapf(err, "failed to convert sheet uid %q to int", tokens[1])+ return "", "", err}- return tokens[0], sheetUID, nil+ return tokens[0], tokens[1], nil}// GetWorksheetUID returns the worksheet UID from a resource name.@@ -507,8 +503,8 @@ func FormatRole(role string) string {return fmt.Sprintf("%s%s", RolePrefix, role)}-func FormatSheet(projectID string, sheetUID int) string {- return fmt.Sprintf("%s/%s%d", FormatProject(projectID), SheetIDPrefix, sheetUID)+func FormatSheet(projectID string, sheetSha256 string) string {+ return fmt.Sprintf("%s/%s%s", FormatProject(projectID), SheetIDPrefix, sheetSha256)}func FormatIssue(projectID string, issueUID int) string {diff --git a/backend/generated-go/store/changelog.pb.go b/backend/generated-go/store/changelog.pb.goindex 3223d1e925..0a1af0b0e8 100644--- a/backend/generated-go/store/changelog.pb.go+++ b/backend/generated-go/store/changelog.pb.go@@ -80,12 +80,11 @@ type ChangelogPayload struct {// The revision uid.// optionalRevision int64 `protobuf:"varint,2,opt,name=revision,proto3" json:"revision,omitempty"`- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- Sheet string `protobuf:"bytes,3,opt,name=sheet,proto3" json:"sheet,omitempty"`- Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"`- Type ChangelogPayload_Type `protobuf:"varint,5,opt,name=type,proto3,enum=bytebase.store.ChangelogPayload_Type" json:"type,omitempty"`- GitCommit string `protobuf:"bytes,6,opt,name=git_commit,json=gitCommit,proto3" json:"git_commit,omitempty"`+ // The SHA256 hash of the sheet content (hex-encoded).+ SheetSha256 string `protobuf:"bytes,3,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`+ Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"`+ Type ChangelogPayload_Type `protobuf:"varint,5,opt,name=type,proto3,enum=bytebase.store.ChangelogPayload_Type" json:"type,omitempty"`+ GitCommit string `protobuf:"bytes,6,opt,name=git_commit,json=gitCommit,proto3" json:"git_commit,omitempty"`// Dump format version for drift detection reliability.// Engine-specific version stored when baseline/migration is created.// 0 = legacy changelog (pre-versioning).@@ -138,9 +137,9 @@ func (x *ChangelogPayload) GetRevision() int64 {return 0}-func (x *ChangelogPayload) GetSheet() string {+func (x *ChangelogPayload) GetSheetSha256() string {if x != nil {- return x.Sheet+ return x.SheetSha256}return ""}@@ -177,11 +176,11 @@ var File_store_changelog_proto protoreflect.FileDescriptorconst file_store_changelog_proto_rawDesc = "" +"\n" +- "\x15store/changelog.proto\x12\x0ebytebase.store\"\xb8\x02\n" ++ "\x15store/changelog.proto\x12\x0ebytebase.store\"\xc5\x02\n" +"\x10ChangelogPayload\x12\x19\n" +"\btask_run\x18\x01 \x01(\tR\ataskRun\x12\x1a\n" +- "\brevision\x18\x02 \x01(\x03R\brevision\x12\x14\n" +- "\x05sheet\x18\x03 \x01(\tR\x05sheet\x12\x18\n" ++ "\brevision\x18\x02 \x01(\x03R\brevision\x12!\n" ++ "\fsheet_sha256\x18\x03 \x01(\tR\vsheetSha256\x12\x18\n" +"\aversion\x18\x04 \x01(\tR\aversion\x129\n" +"\x04type\x18\x05 \x01(\x0e2%.bytebase.store.ChangelogPayload.TypeR\x04type\x12\x1d\n" +"\n" +diff --git a/backend/generated-go/store/changelog_equal.pb.go b/backend/generated-go/store/changelog_equal.pb.goindex 822696c796..3bb2b383c3 100644--- a/backend/generated-go/store/changelog_equal.pb.go+++ b/backend/generated-go/store/changelog_equal.pb.go@@ -16,7 +16,7 @@ func (x *ChangelogPayload) Equal(y *ChangelogPayload) bool {if x.Revision != y.Revision {return false}- if x.Sheet != y.Sheet {+ if x.SheetSha256 != y.SheetSha256 {return false}if x.Version != y.Version {diff --git a/backend/generated-go/store/issue_comment.pb.go b/backend/generated-go/store/issue_comment.pb.goindex 96f69f9d7a..24402bb1d3 100644--- a/backend/generated-go/store/issue_comment.pb.go+++ b/backend/generated-go/store/issue_comment.pb.go@@ -277,10 +277,10 @@ type IssueCommentPayload_PlanSpecUpdate struct {// The spec that was updated// Format: projects/{project}/plans/{plan}/specs/{spec}Spec string `protobuf:"bytes,1,opt,name=spec,proto3" json:"spec,omitempty"`- // Format: projects/{project}/sheets/{sheet}- FromSheet *string `protobuf:"bytes,2,opt,name=from_sheet,json=fromSheet,proto3,oneof" json:"from_sheet,omitempty"`- // Format: projects/{project}/sheets/{sheet}- ToSheet *string `protobuf:"bytes,3,opt,name=to_sheet,json=toSheet,proto3,oneof" json:"to_sheet,omitempty"`+ // The SHA256 hash of the previous sheet content (hex-encoded).+ FromSheetSha256 *string `protobuf:"bytes,2,opt,name=from_sheet_sha256,json=fromSheetSha256,proto3,oneof" json:"from_sheet_sha256,omitempty"`+ // The SHA256 hash of the new sheet content (hex-encoded).+ ToSheetSha256 *string `protobuf:"bytes,3,opt,name=to_sheet_sha256,json=toSheetSha256,proto3,oneof" json:"to_sheet_sha256,omitempty"`unknownFields protoimpl.UnknownFieldssizeCache protoimpl.SizeCache}@@ -322,16 +322,16 @@ func (x *IssueCommentPayload_PlanSpecUpdate) GetSpec() string {return ""}-func (x *IssueCommentPayload_PlanSpecUpdate) GetFromSheet() string {- if x != nil && x.FromSheet != nil {- return *x.FromSheet+func (x *IssueCommentPayload_PlanSpecUpdate) GetFromSheetSha256() string {+ if x != nil && x.FromSheetSha256 != nil {+ return *x.FromSheetSha256}return ""}-func (x *IssueCommentPayload_PlanSpecUpdate) GetToSheet() string {- if x != nil && x.ToSheet != nil {- return *x.ToSheet+func (x *IssueCommentPayload_PlanSpecUpdate) GetToSheetSha256() string {+ if x != nil && x.ToSheetSha256 != nil {+ return *x.ToSheetSha256}return ""}@@ -340,7 +340,7 @@ var File_store_issue_comment_proto protoreflect.FileDescriptorconst file_store_issue_comment_proto_rawDesc = "" +"\n" +- "\x19store/issue_comment.proto\x12\x0ebytebase.store\x1a\x14store/approval.proto\x1a\x11store/issue.proto\"\xef\a\n" ++ "\x19store/issue_comment.proto\x12\x0ebytebase.store\x1a\x14store/approval.proto\x1a\x11store/issue.proto\"\x97\b\n" +"\x13IssueCommentPayload\x12\x18\n" +"\acomment\x18\x01 \x01(\tR\acomment\x12J\n" +"\bapproval\x18\x02 \x01(\v2,.bytebase.store.IssueCommentPayload.ApprovalH\x00R\bapproval\x12T\n" +@@ -366,14 +366,13 @@ const file_store_issue_comment_proto_rawDesc = "" +"\x0f_to_descriptionB\x0e\n" +"\f_from_statusB\f\n" +"\n" +- "_to_status\x1a\x84\x01\n" ++ "_to_status\x1a\xac\x01\n" +"\x0ePlanSpecUpdate\x12\x12\n" +- "\x04spec\x18\x01 \x01(\tR\x04spec\x12\"\n" +- "\n" +- "from_sheet\x18\x02 \x01(\tH\x00R\tfromSheet\x88\x01\x01\x12\x1e\n" +- "\bto_sheet\x18\x03 \x01(\tH\x01R\atoSheet\x88\x01\x01B\r\n" +- "\v_from_sheetB\v\n" +- "\t_to_sheetB\a\n" ++ "\x04spec\x18\x01 \x01(\tR\x04spec\x12/\n" ++ "\x11from_sheet_sha256\x18\x02 \x01(\tH\x00R\x0ffromSheetSha256\x88\x01\x01\x12+\n" ++ "\x0fto_sheet_sha256\x18\x03 \x01(\tH\x01R\rtoSheetSha256\x88\x01\x01B\x14\n" ++ "\x12_from_sheet_sha256B\x12\n" ++ "\x10_to_sheet_sha256B\a\n" +"\x05eventB\x94\x01\n" +"\x12com.bytebase.storeB\x11IssueCommentProtoP\x01Z\x12generated-go/store\xa2\x02\x03BSX\xaa\x02\x0eBytebase.Store\xca\x02\x0eBytebase\\Store\xe2\x02\x1aBytebase\\Store\\GPBMetadata\xea\x02\x0fBytebase::Storeb\x06proto3"diff --git a/backend/generated-go/store/issue_comment_equal.pb.go b/backend/generated-go/store/issue_comment_equal.pb.goindex 42a3e283ef..551566cfd2 100644--- a/backend/generated-go/store/issue_comment_equal.pb.go+++ b/backend/generated-go/store/issue_comment_equal.pb.go@@ -70,10 +70,10 @@ func (x *IssueCommentPayload_PlanSpecUpdate) Equal(y *IssueCommentPayload_PlanSpif x.Spec != y.Spec {return false}- if p, q := x.FromSheet, y.FromSheet; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {+ if p, q := x.FromSheetSha256, y.FromSheetSha256; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {return false}- if p, q := x.ToSheet, y.ToSheet; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {+ if p, q := x.ToSheetSha256, y.ToSheetSha256; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {return false}return truediff --git a/backend/generated-go/store/plan.pb.go b/backend/generated-go/store/plan.pb.goindex 63a0d2425d..9c26a5179d 100644--- a/backend/generated-go/store/plan.pb.go+++ b/backend/generated-go/store/plan.pb.go@@ -350,9 +350,8 @@ type PlanConfig_ChangeDatabaseConfig struct {// Multi-database format: [instances/{instance-id}/databases/{database-name}].// Single database group format: [projects/{project}/databaseGroups/{databaseGroup}].Targets []string `protobuf:"bytes,10,rep,name=targets,proto3" json:"targets,omitempty"`- // The resource name of the sheet.- // Format: projects/{project}/sheets/{sheet}- Sheet string `protobuf:"bytes,2,opt,name=sheet,proto3" json:"sheet,omitempty"`+ // The SHA256 hash of the sheet content (hex-encoded).+ SheetSha256 string `protobuf:"bytes,2,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`// The resource name of the release.// Format: projects/{project}/releases/{release}Release string `protobuf:"bytes,9,opt,name=release,proto3" json:"release,omitempty"`@@ -403,9 +402,9 @@ func (x *PlanConfig_ChangeDatabaseConfig) GetTargets() []string {return nil}-func (x *PlanConfig_ChangeDatabaseConfig) GetSheet() string {+func (x *PlanConfig_ChangeDatabaseConfig) GetSheetSha256() string {if x != nil {- return x.Sheet+ return x.SheetSha256}return ""}@@ -451,9 +450,8 @@ type PlanConfig_ExportDataConfig struct {// Multi-database format: [instances/{instance-id}/databases/{database-name}].// Single database group format: [projects/{project}/databaseGroups/{databaseGroup}].Targets []string `protobuf:"bytes,5,rep,name=targets,proto3" json:"targets,omitempty"`- // The resource name of the sheet.- // Format: projects/{project}/sheets/{sheet}- Sheet string `protobuf:"bytes,2,opt,name=sheet,proto3" json:"sheet,omitempty"`+ // The SHA256 hash of the sheet content (hex-encoded).+ SheetSha256 string `protobuf:"bytes,2,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`// The format of the exported file.Format ExportFormat `protobuf:"varint,3,opt,name=format,proto3,enum=bytebase.store.ExportFormat" json:"format,omitempty"`// The zip password provided by users.@@ -500,9 +498,9 @@ func (x *PlanConfig_ExportDataConfig) GetTargets() []string {return nil}-func (x *PlanConfig_ExportDataConfig) GetSheet() string {+func (x *PlanConfig_ExportDataConfig) GetSheetSha256() string {if x != nil {- return x.Sheet+ return x.SheetSha256}return ""}@@ -633,7 +631,7 @@ var File_store_plan_proto protoreflect.FileDescriptorconst file_store_plan_proto_rawDesc = "" +"\n" +- "\x10store/plan.proto\x12\x0ebytebase.store\x1a\x1fgoogle/api/field_behavior.proto\x1a\x12store/common.proto\"\xfe\f\n" ++ "\x10store/plan.proto\x12\x0ebytebase.store\x1a\x1fgoogle/api/field_behavior.proto\x1a\x12store/common.proto\"\x98\r\n" +"\n" +"PlanConfig\x125\n" +"\x05specs\x18\x01 \x03(\v2\x1f.bytebase.store.PlanConfig.SpecR\x05specs\x12E\n" +@@ -654,11 +652,11 @@ const file_store_plan_proto_rawDesc = "" +"\tcollation\x18\x05 \x01(\tB\x03\xe0A\x01R\tcollation\x12\x1d\n" +"\acluster\x18\x06 \x01(\tB\x03\xe0A\x01R\acluster\x12\x19\n" +"\x05owner\x18\a \x01(\tB\x03\xe0A\x01R\x05owner\x12%\n" +- "\venvironment\x18\t \x01(\tB\x03\xe0A\x01R\venvironment\x1a\xd2\x03\n" ++ "\venvironment\x18\t \x01(\tB\x03\xe0A\x01R\venvironment\x1a\xdf\x03\n" +"\x14ChangeDatabaseConfig\x12\x18\n" +"\atargets\x18\n" +- " \x03(\tR\atargets\x12\x14\n" +- "\x05sheet\x18\x02 \x01(\tR\x05sheet\x12\x18\n" ++ " \x03(\tR\atargets\x12!\n" ++ "\fsheet_sha256\x18\x02 \x01(\tR\vsheetSha256\x12\x18\n" +"\arelease\x18\t \x01(\tR\arelease\x12H\n" +"\x04type\x18\x03 \x01(\x0e24.bytebase.store.PlanConfig.ChangeDatabaseConfig.TypeR\x04type\x12`\n" +"\vghost_flags\x18\a \x03(\v2?.bytebase.store.PlanConfig.ChangeDatabaseConfig.GhostFlagsEntryR\n" +@@ -671,10 +669,10 @@ const file_store_plan_proto_rawDesc = "" +"\x04Type\x12\x14\n" +"\x10TYPE_UNSPECIFIED\x10\x00\x12\v\n" +"\aMIGRATE\x10\x01\x12\a\n" +- "\x03SDL\x10\x02\x1a\xa6\x01\n" ++ "\x03SDL\x10\x02\x1a\xb3\x01\n" +"\x10ExportDataConfig\x12\x18\n" +- "\atargets\x18\x05 \x03(\tR\atargets\x12\x14\n" +- "\x05sheet\x18\x02 \x01(\tR\x05sheet\x124\n" ++ "\atargets\x18\x05 \x03(\tR\atargets\x12!\n" ++ "\fsheet_sha256\x18\x02 \x01(\tR\vsheetSha256\x124\n" +"\x06format\x18\x03 \x01(\x0e2\x1c.bytebase.store.ExportFormatR\x06format\x12\x1f\n" +"\bpassword\x18\x04 \x01(\tH\x00R\bpassword\x88\x01\x01B\v\n" +"\t_password\x1a\x81\x02\n" +diff --git a/backend/generated-go/store/plan_check_run.pb.go b/backend/generated-go/store/plan_check_run.pb.goindex e19b5f5b71..3f3897445f 100644--- a/backend/generated-go/store/plan_check_run.pb.go+++ b/backend/generated-go/store/plan_check_run.pb.go@@ -22,11 +22,12 @@ const ()type PlanCheckRunConfig struct {- state protoimpl.MessageState `protogen:"open.v1"`- SheetUid int32 `protobuf:"varint,1,opt,name=sheet_uid,json=sheetUid,proto3" json:"sheet_uid,omitempty"`- InstanceId string `protobuf:"bytes,2,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"`- DatabaseName string `protobuf:"bytes,3,opt,name=database_name,json=databaseName,proto3" json:"database_name,omitempty"`- GhostFlags map[string]string `protobuf:"bytes,4,rep,name=ghost_flags,json=ghostFlags,proto3" json:"ghost_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`+ state protoimpl.MessageState `protogen:"open.v1"`+ // The SHA256 hash of the sheet content (hex-encoded).+ SheetSha256 string `protobuf:"bytes,1,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`+ InstanceId string `protobuf:"bytes,2,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"`+ DatabaseName string `protobuf:"bytes,3,opt,name=database_name,json=databaseName,proto3" json:"database_name,omitempty"`+ GhostFlags map[string]string `protobuf:"bytes,4,rep,name=ghost_flags,json=ghostFlags,proto3" json:"ghost_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`// If set, a backup of the modified data will be created automatically before any changes are applied.EnablePriorBackup bool `protobuf:"varint,5,opt,name=enable_prior_backup,json=enablePriorBackup,proto3" json:"enable_prior_backup,omitempty"`// Whether to use gh-ost for online schema migration.@@ -67,11 +68,11 @@ func (*PlanCheckRunConfig) Descriptor() ([]byte, []int) {return file_store_plan_check_run_proto_rawDescGZIP(), []int{0}}-func (x *PlanCheckRunConfig) GetSheetUid() int32 {+func (x *PlanCheckRunConfig) GetSheetSha256() string {if x != nil {- return x.SheetUid+ return x.SheetSha256}- return 0+ return ""}func (x *PlanCheckRunConfig) GetInstanceId() string {@@ -601,9 +602,9 @@ var File_store_plan_check_run_proto protoreflect.FileDescriptorconst file_store_plan_check_run_proto_rawDesc = "" +"\n" +- "\x1astore/plan_check_run.proto\x12\x0ebytebase.store\x1a\x12store/advice.proto\x1a\x12store/common.proto\"\xfd\x02\n" +- "\x12PlanCheckRunConfig\x12\x1b\n" +- "\tsheet_uid\x18\x01 \x01(\x05R\bsheetUid\x12\x1f\n" ++ "\x1astore/plan_check_run.proto\x12\x0ebytebase.store\x1a\x12store/advice.proto\x1a\x12store/common.proto\"\x83\x03\n" ++ "\x12PlanCheckRunConfig\x12!\n" ++ "\fsheet_sha256\x18\x01 \x01(\tR\vsheetSha256\x12\x1f\n" +"\vinstance_id\x18\x02 \x01(\tR\n" +"instanceId\x12#\n" +"\rdatabase_name\x18\x03 \x01(\tR\fdatabaseName\x12S\n" +diff --git a/backend/generated-go/store/plan_check_run_equal.pb.go b/backend/generated-go/store/plan_check_run_equal.pb.goindex 70852d75d6..1da4844c8d 100644--- a/backend/generated-go/store/plan_check_run_equal.pb.go+++ b/backend/generated-go/store/plan_check_run_equal.pb.go@@ -10,7 +10,7 @@ func (x *PlanCheckRunConfig) Equal(y *PlanCheckRunConfig) bool {if x == nil || y == nil {return x == nil && y == nil}- if x.SheetUid != y.SheetUid {+ if x.SheetSha256 != y.SheetSha256 {return false}if x.InstanceId != y.InstanceId {diff --git a/backend/generated-go/store/plan_equal.pb.go b/backend/generated-go/store/plan_equal.pb.goindex dfaff5fcc0..bcb224ae69 100644--- a/backend/generated-go/store/plan_equal.pb.go+++ b/backend/generated-go/store/plan_equal.pb.go@@ -74,7 +74,7 @@ func (x *PlanConfig_ChangeDatabaseConfig) Equal(y *PlanConfig_ChangeDatabaseConfreturn false}}- if x.Sheet != y.Sheet {+ if x.SheetSha256 != y.SheetSha256 {return false}if x.Release != y.Release {@@ -119,7 +119,7 @@ func (x *PlanConfig_ExportDataConfig) Equal(y *PlanConfig_ExportDataConfig) boolreturn false}}- if x.Sheet != y.Sheet {+ if x.SheetSha256 != y.SheetSha256 {return false}if x.Format != y.Format {diff --git a/backend/generated-go/store/release.pb.go b/backend/generated-go/store/release.pb.goindex 615c8e7ef1..b94e4aecba 100644--- a/backend/generated-go/store/release.pb.go+++ b/backend/generated-go/store/release.pb.go@@ -7,7 +7,6 @@package storeimport (- _ "google.golang.org/genproto/googleapis/api/annotations"protoreflect "google.golang.org/protobuf/reflect/protoreflect"protoimpl "google.golang.org/protobuf/runtime/protoimpl"reflect "reflect"@@ -88,10 +87,7 @@ type ReleasePayload_File struct {Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`// The path of the file, e.g., `2.2/V0001_create_table.sql`.Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- Sheet string `protobuf:"bytes,3,opt,name=sheet,proto3" json:"sheet,omitempty"`- // The SHA256 hash value of the sheet.+ // The SHA256 hash of the sheet content (hex-encoded).SheetSha256 string `protobuf:"bytes,4,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`Type SchemaChangeType `protobuf:"varint,5,opt,name=type,proto3,enum=bytebase.store.SchemaChangeType" json:"type,omitempty"`Version string `protobuf:"bytes,6,opt,name=version,proto3" json:"version,omitempty"`@@ -145,13 +141,6 @@ func (x *ReleasePayload_File) GetPath() string {return ""}-func (x *ReleasePayload_File) GetSheet() string {- if x != nil {- return x.Sheet- }- return ""-}-func (x *ReleasePayload_File) GetSheetSha256() string {if x != nil {return x.SheetSha256@@ -236,21 +225,19 @@ var File_store_release_proto protoreflect.FileDescriptorconst file_store_release_proto_rawDesc = "" +"\n" +- "\x13store/release.proto\x12\x0ebytebase.store\x1a\x19google/api/resource.proto\x1a\x12store/common.proto\"\xef\x03\n" ++ "\x13store/release.proto\x12\x0ebytebase.store\x1a\x12store/common.proto\"\xc6\x03\n" +"\x0eReleasePayload\x12\x14\n" +"\x05title\x18\x01 \x01(\tR\x05title\x129\n" +"\x05files\x18\x02 \x03(\v2#.bytebase.store.ReleasePayload.FileR\x05files\x12G\n" +"\n" +- "vcs_source\x18\x03 \x01(\v2(.bytebase.store.ReleasePayload.VCSSourceR\tvcsSource\x1a\xef\x01\n" ++ "vcs_source\x18\x03 \x01(\v2(.bytebase.store.ReleasePayload.VCSSourceR\tvcsSource\x1a\xc6\x01\n" +"\x04File\x12\x0e\n" +"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +- "\x04path\x18\x02 \x01(\tR\x04path\x12-\n" +- "\x05sheet\x18\x03 \x01(\tB\x17\xfaA\x14\n" +- "\x12bytebase.com/SheetR\x05sheet\x12!\n" ++ "\x04path\x18\x02 \x01(\tR\x04path\x12!\n" +"\fsheet_sha256\x18\x04 \x01(\tR\vsheetSha256\x124\n" +"\x04type\x18\x05 \x01(\x0e2 .bytebase.store.SchemaChangeTypeR\x04type\x12\x18\n" +"\aversion\x18\x06 \x01(\tR\aversion\x12!\n" +- "\fenable_ghost\x18\a \x01(\bR\venableGhost\x1aQ\n" ++ "\fenable_ghost\x18\a \x01(\bR\venableGhostJ\x04\b\x03\x10\x04\x1aQ\n" +"\tVCSSource\x122\n" +"\bvcs_type\x18\x01 \x01(\x0e2\x17.bytebase.store.VCSTypeR\avcsType\x12\x10\n" +"\x03url\x18\x02 \x01(\tR\x03urlB\x8f\x01\n" +diff --git a/backend/generated-go/store/release_equal.pb.go b/backend/generated-go/store/release_equal.pb.goindex 5416c055ef..fba592d26d 100644--- a/backend/generated-go/store/release_equal.pb.go+++ b/backend/generated-go/store/release_equal.pb.go@@ -16,9 +16,6 @@ func (x *ReleasePayload_File) Equal(y *ReleasePayload_File) bool {if x.Path != y.Path {return false}- if x.Sheet != y.Sheet {- return false- }if x.SheetSha256 != y.SheetSha256 {return false}diff --git a/backend/generated-go/store/revision.pb.go b/backend/generated-go/store/revision.pb.goindex 09973a0b23..cb260a4969 100644--- a/backend/generated-go/store/revision.pb.go+++ b/backend/generated-go/store/revision.pb.go@@ -30,10 +30,7 @@ type RevisionPayload struct {// Format: projects/{project}/releases/{release}/files/{id}// Can be empty.File string `protobuf:"bytes,2,opt,name=file,proto3" json:"file,omitempty"`- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- Sheet string `protobuf:"bytes,3,opt,name=sheet,proto3" json:"sheet,omitempty"`- // The SHA256 hash value of the sheet.+ // The SHA256 hash of the sheet content (hex-encoded).SheetSha256 string `protobuf:"bytes,4,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`// The task run associated with the revision.// Can be empty.@@ -89,13 +86,6 @@ func (x *RevisionPayload) GetFile() string {return ""}-func (x *RevisionPayload) GetSheet() string {- if x != nil {- return x.Sheet- }- return ""-}-func (x *RevisionPayload) GetSheetSha256() string {if x != nil {return x.SheetSha256@@ -121,17 +111,15 @@ var File_store_revision_proto protoreflect.FileDescriptorconst file_store_revision_proto_rawDesc = "" +"\n" +- "\x14store/revision.proto\x12\x0ebytebase.store\x1a\x19google/api/resource.proto\x1a\x12store/common.proto\"\x98\x02\n" ++ "\x14store/revision.proto\x12\x0ebytebase.store\x1a\x19google/api/resource.proto\x1a\x12store/common.proto\"\xef\x01\n" +"\x0fRevisionPayload\x123\n" +"\arelease\x18\x01 \x01(\tB\x19\xfaA\x16\n" +"\x14bytebase.com/ReleaseR\arelease\x12\x12\n" +- "\x04file\x18\x02 \x01(\tR\x04file\x12-\n" +- "\x05sheet\x18\x03 \x01(\tB\x17\xfaA\x14\n" +- "\x12bytebase.com/SheetR\x05sheet\x12!\n" ++ "\x04file\x18\x02 \x01(\tR\x04file\x12!\n" +"\fsheet_sha256\x18\x04 \x01(\tR\vsheetSha256\x124\n" +"\btask_run\x18\x05 \x01(\tB\x19\xfaA\x16\n" +"\x14bytebase.com/TaskRunR\ataskRun\x124\n" +- "\x04type\x18\x06 \x01(\x0e2 .bytebase.store.SchemaChangeTypeR\x04typeB\x90\x01\n" ++ "\x04type\x18\x06 \x01(\x0e2 .bytebase.store.SchemaChangeTypeR\x04typeJ\x04\b\x03\x10\x04B\x90\x01\n" +"\x12com.bytebase.storeB\rRevisionProtoP\x01Z\x12generated-go/store\xa2\x02\x03BSX\xaa\x02\x0eBytebase.Store\xca\x02\x0eBytebase\\Store\xe2\x02\x1aBytebase\\Store\\GPBMetadata\xea\x02\x0fBytebase::Storeb\x06proto3"var (diff --git a/backend/generated-go/store/revision_equal.pb.go b/backend/generated-go/store/revision_equal.pb.goindex db6f537311..233ad306ea 100644--- a/backend/generated-go/store/revision_equal.pb.go+++ b/backend/generated-go/store/revision_equal.pb.go@@ -16,9 +16,6 @@ func (x *RevisionPayload) Equal(y *RevisionPayload) bool {if x.File != y.File {return false}- if x.Sheet != y.Sheet {- return false- }if x.SheetSha256 != y.SheetSha256 {return false}diff --git a/backend/generated-go/store/task.pb.go b/backend/generated-go/store/task.pb.goindex 1d720c7523..7c937f7256 100644--- a/backend/generated-go/store/task.pb.go+++ b/backend/generated-go/store/task.pb.go@@ -90,8 +90,8 @@ type Task struct {SkippedReason string `protobuf:"bytes,2,opt,name=skipped_reason,json=skippedReason,proto3" json:"skipped_reason,omitempty"`// UUID that identifies the spec this task implements.SpecId string `protobuf:"bytes,3,opt,name=spec_id,json=specId,proto3" json:"spec_id,omitempty"`- // The sheet ID containing SQL statements for this task.- SheetId int32 `protobuf:"varint,4,opt,name=sheet_id,json=sheetId,proto3" json:"sheet_id,omitempty"`+ // The SHA256 hash of the sheet content (hex-encoded).+ SheetSha256 string `protobuf:"bytes,4,opt,name=sheet_sha256,json=sheetSha256,proto3" json:"sheet_sha256,omitempty"`// The environment where the database will be created.EnvironmentId string `protobuf:"bytes,5,opt,name=environment_id,json=environmentId,proto3" json:"environment_id,omitempty"`// Name of the database to create.@@ -171,11 +171,11 @@ func (x *Task) GetSpecId() string {return ""}-func (x *Task) GetSheetId() int32 {+func (x *Task) GetSheetSha256() string {if x != nil {- return x.SheetId+ return x.SheetSha256}- return 0+ return ""}func (x *Task) GetEnvironmentId() string {@@ -313,12 +313,12 @@ var File_store_task_proto protoreflect.FileDescriptorconst file_store_task_proto_rawDesc = "" +"\n" +- "\x10store/task.proto\x12\x0ebytebase.store\x1a\x12store/common.proto\"\xae\x06\n" ++ "\x10store/task.proto\x12\x0ebytebase.store\x1a\x12store/common.proto\"\xb6\x06\n" +"\x04Task\x12\x18\n" +"\askipped\x18\x01 \x01(\bR\askipped\x12%\n" +"\x0eskipped_reason\x18\x02 \x01(\tR\rskippedReason\x12\x17\n" +- "\aspec_id\x18\x03 \x01(\tR\x06specId\x12\x19\n" +- "\bsheet_id\x18\x04 \x01(\x05R\asheetId\x12%\n" ++ "\aspec_id\x18\x03 \x01(\tR\x06specId\x12!\n" ++ "\fsheet_sha256\x18\x04 \x01(\tR\vsheetSha256\x12%\n" +"\x0eenvironment_id\x18\x05 \x01(\tR\renvironmentId\x12#\n" +"\rdatabase_name\x18\x06 \x01(\tR\fdatabaseName\x12\x1d\n" +"\n" +diff --git a/backend/generated-go/store/task_equal.pb.go b/backend/generated-go/store/task_equal.pb.goindex 1c2e268f5c..21df11d25a 100644--- a/backend/generated-go/store/task_equal.pb.go+++ b/backend/generated-go/store/task_equal.pb.go@@ -19,7 +19,7 @@ func (x *Task) Equal(y *Task) bool {if x.SpecId != y.SpecId {return false}- if x.SheetId != y.SheetId {+ if x.SheetSha256 != y.SheetSha256 {return false}if x.EnvironmentId != y.EnvironmentId {diff --git a/backend/migrator/migration/3.14/0000##sheet_content_addressed.sql b/backend/migrator/migration/3.14/0000##sheet_content_addressed.sqlnew file mode 100644index 0000000000..4f7ee26a55--- /dev/null+++ b/backend/migrator/migration/3.14/0000##sheet_content_addressed.sql@@ -0,0 +1,137 @@+-- Add new column with sha256 reference to task_run+ALTER TABLE task_run ADD COLUMN sheet_sha256 bytea REFERENCES sheet_blob(sha256);++-- Backfill task_run.sheet_sha256 from sheet table+UPDATE task_run tr+SET sheet_sha256 = s.sha256+FROM sheet s+WHERE tr.sheet_id = s.id;++-- Backfill task.payload JSONB (Task proto)+-- Converts sheetId (int) to sheetSha256 (hex string)+UPDATE task t+SET payload = jsonb_set(+ payload - 'sheetId',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE (t.payload->>'sheetId')::int = s.id+AND t.payload ? 'sheetId';++-- Backfill plan_check_run.config JSONB (PlanCheckRunConfig proto)+-- Converts sheetUid (int) to sheetSha256 (hex string)+UPDATE plan_check_run pcr+SET config = jsonb_set(+ config - 'sheetUid',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE (pcr.config->>'sheetUid')::int = s.id+AND pcr.config ? 'sheetUid';++-- Backfill changelog.payload JSONB (ChangelogPayload proto)+-- Converts sheet resource name to sheetSha256 field+UPDATE changelog c+SET payload = jsonb_set(+ payload - 'sheet',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE s.id = (regexp_match(payload->>'sheet', '/sheets/(\d+)$'))[1]::int+AND payload ? 'sheet';++-- Backfill issue_comment.payload JSONB (IssueCommentPayload.PlanSpecUpdate proto)+-- Converts fromSheet and toSheet resource names to fromSheetSha256 and toSheetSha256 fields+UPDATE issue_comment ic+SET payload = jsonb_set(+ payload #- '{planSpecUpdate,fromSheet}',+ '{planSpecUpdate,fromSheetSha256}',+ to_jsonb(encode(s1.sha256, 'hex'))+)+FROM sheet s1+WHERE s1.id = (regexp_match(payload #>> '{planSpecUpdate,fromSheet}', '/sheets/(\d+)$'))[1]::int+AND payload #> '{planSpecUpdate,fromSheet}' IS NOT NULL;++UPDATE issue_comment ic+SET payload = jsonb_set(+ payload #- '{planSpecUpdate,toSheet}',+ '{planSpecUpdate,toSheetSha256}',+ to_jsonb(encode(s2.sha256, 'hex'))+)+FROM sheet s2+WHERE s2.id = (regexp_match(payload #>> '{planSpecUpdate,toSheet}', '/sheets/(\d+)$'))[1]::int+AND payload #> '{planSpecUpdate,toSheet}' IS NOT NULL;++-- Backfill plan.config JSONB (PlanConfig proto)+-- Converts sheet resource names to sheetSha256 fields in specs array+UPDATE plan p+SET config = (+ SELECT jsonb_set(+ p.config,+ '{specs}',+ jsonb_agg(+ CASE+ WHEN spec #> '{changeDatabaseConfig,sheet}' IS NOT NULL THEN+ jsonb_set(+ spec #- '{changeDatabaseConfig,sheet}',+ '{changeDatabaseConfig,sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+ )+ WHEN spec #> '{exportDataConfig,sheet}' IS NOT NULL THEN+ jsonb_set(+ spec #- '{exportDataConfig,sheet}',+ '{exportDataConfig,sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+ )+ ELSE spec+ END+ )+ )+ FROM jsonb_array_elements(p.config->'specs') AS spec+ LEFT JOIN sheet s ON s.id = COALESCE(+ (regexp_match(spec #>> '{changeDatabaseConfig,sheet}', '/sheets/(\d+)$'))[1]::int,+ (regexp_match(spec #>> '{exportDataConfig,sheet}', '/sheets/(\d+)$'))[1]::int+ )+)+WHERE config->'specs' IS NOT NULL;++-- Backfill revision.payload JSONB (RevisionPayload proto)+-- Converts sheet resource name to sheetSha256 field+UPDATE revision r+SET payload = jsonb_set(+ payload - 'sheet',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE s.id = (regexp_match(payload->>'sheet', '/sheets/(\d+)$'))[1]::int+AND payload ? 'sheet';++-- Backfill release.payload JSONB (ReleasePayload proto)+-- Converts sheet resource names to sheetSha256 fields in files array+UPDATE release r+SET payload = (+ SELECT jsonb_set(+ r.payload,+ '{files}',+ jsonb_agg(+ jsonb_set(+ file - 'sheet',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+ )+ )+ )+ FROM jsonb_array_elements(r.payload->'files') AS file+ LEFT JOIN sheet s ON s.id = (regexp_match(file->>'sheet', '/sheets/(\d+)$'))[1]::int+)+WHERE payload->'files' IS NOT NULL;++-- Drop old column+ALTER TABLE task_run DROP COLUMN sheet_id;++-- Note: sheet table is kept for now and will be dropped in a future migration+-- after confirming all references have been successfully migrateddiff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sqlindex 26b1ce8e1c..a2ce6e2c87 100644--- a/backend/migrator/migration/LATEST.sql+++ b/backend/migrator/migration/LATEST.sql@@ -224,7 +224,7 @@ CREATE TABLE task_run (created_at timestamptz NOT NULL DEFAULT now(),updated_at timestamptz NOT NULL DEFAULT now(),task_id integer NOT NULL REFERENCES task(id),- sheet_id integer REFERENCES sheet(id),+ sheet_sha256 bytea REFERENCES sheet_blob(sha256),attempt integer NOT NULL,status text NOT NULL CHECK (status IN ('PENDING', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),started_at timestamptz NULL,diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex 55d8b47626..a908c06266 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -12,7 +12,7 @@ import (func TestLatestVersion(t *testing.T) {files, err := getSortedVersionedFiles()require.NoError(t, err)- require.Equal(t, semver.MustParse("3.13.31"), *files[len(files)-1].version)+ require.Equal(t, semver.MustParse("3.14.0"), *files[len(files)-1].version)}func TestVersionUnique(t *testing.T) {diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.goindex 0237c9463d..841e78dcdf 100644--- a/backend/runner/approval/runner.go+++ b/backend/runner/approval/runner.go@@ -500,11 +500,11 @@ func (r *Runner) buildCELVariablesForDatabaseChange(ctx context.Context, issue *}taskStatement := ""- sheetUID := int(task.Payload.GetSheetId())- if sheetUID != 0 {- sheet, err := r.store.GetSheetFull(ctx, sheetUID)+ sheetSha256 := task.Payload.GetSheetSha256()+ if sheetSha256 != "" {+ sheet, err := r.store.GetSheetFull(ctx, sheetSha256)if err != nil {- return nil, true, errors.Wrapf(err, "failed to get statement in sheet %v", sheetUID)+ return nil, true, errors.Wrapf(err, "failed to get statement in sheet %v", sheetSha256)}taskStatement = sheet.Statement}diff --git a/backend/runner/plancheck/ghost_sync_executor.go b/backend/runner/plancheck/ghost_sync_executor.goindex 2f86f4f004..b79d306ed6 100644--- a/backend/runner/plancheck/ghost_sync_executor.go+++ b/backend/runner/plancheck/ghost_sync_executor.go@@ -83,10 +83,9 @@ func (e *GhostSyncExecutor) Run(ctx context.Context, config *storepb.PlanCheckRureturn nil, common.Errorf(common.Internal, "admin data source not found for instance %s", instance.ResourceID)}- sheetUID := int(config.SheetUid)- sheet, err := e.store.GetSheetFull(ctx, sheetUID)+ sheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %d", sheetUID)+ return nil, errors.Wrapf(err, "failed to get sheet %s", config.SheetSha256)}statement := sheet.Statementdiff --git a/backend/runner/plancheck/statement_advise_executor.go b/backend/runner/plancheck/statement_advise_executor.goindex c1d31537e8..59bd0b2338 100644--- a/backend/runner/plancheck/statement_advise_executor.go+++ b/backend/runner/plancheck/statement_advise_executor.go@@ -45,10 +45,9 @@ type StatementAdviseExecutor struct {// Run will run the plan check statement advise executor once, and run its sub-advisors one-by-one.func (e *StatementAdviseExecutor) Run(ctx context.Context, config *storepb.PlanCheckRunConfig) ([]*storepb.PlanCheckRunResult_Result, error) {- sheetUID := int(config.SheetUid)- sheet, err := e.store.GetSheetMetadata(ctx, sheetUID)+ sheet, err := e.store.GetSheetMetadata(ctx, config.SheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %d", sheetUID)+ return nil, errors.Wrapf(err, "failed to get sheet %s", config.SheetSha256)}if sheet.Size > common.MaxSheetCheckSize {return []*storepb.PlanCheckRunResult_Result{@@ -60,7 +59,7 @@ func (e *StatementAdviseExecutor) Run(ctx context.Context, config *storepb.PlanC},}, nil}- fullSheet, err := e.store.GetSheetFull(ctx, sheetUID)+ fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)if err != nil {return nil, err}diff --git a/backend/runner/plancheck/statement_report_executor.go b/backend/runner/plancheck/statement_report_executor.goindex 73338b3afa..15164f5678 100644--- a/backend/runner/plancheck/statement_report_executor.go+++ b/backend/runner/plancheck/statement_report_executor.go@@ -48,10 +48,9 @@ type StatementReportExecutor struct {// Run runs the statement report executor.func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanCheckRunConfig) ([]*storepb.PlanCheckRunResult_Result, error) {- sheetUID := int(config.SheetUid)- sheet, err := e.store.GetSheetMetadata(ctx, sheetUID)+ sheet, err := e.store.GetSheetMetadata(ctx, config.SheetSha256)if err != nil {- return nil, errors.Wrapf(err, "failed to get sheet %d", sheetUID)+ return nil, errors.Wrapf(err, "failed to get sheet %s", config.SheetSha256)}if sheet.Size > common.MaxSheetCheckSize {return []*storepb.PlanCheckRunResult_Result{@@ -63,7 +62,7 @@ func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanC},}, nil}- fullSheet, err := e.store.GetSheetFull(ctx, sheetUID)+ fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)if err != nil {return nil, err}diff --git a/backend/runner/taskrun/auto_rollout_scheduler.go b/backend/runner/taskrun/auto_rollout_scheduler.goindex d85ec24d99..b7c05b87b6 100644--- a/backend/runner/taskrun/auto_rollout_scheduler.go+++ b/backend/runner/taskrun/auto_rollout_scheduler.go@@ -156,9 +156,9 @@ func (s *Scheduler) scheduleAutoRolloutTask(ctx context.Context, taskUID int) ercreate := &store.TaskRunMessage{TaskUID: task.ID,}- if task.Payload.GetSheetId() != 0 {- sheetUID := int(task.Payload.GetSheetId())- create.SheetUID = &sheetUID+ if task.Payload.GetSheetSha256() != "" {+ sheetSha256 := task.Payload.GetSheetSha256()+ create.SheetSha256 = &sheetSha256}if err := s.store.CreatePendingTaskRuns(ctx, common.SystemBotEmail, create); err != nil {diff --git a/backend/runner/taskrun/data_export_executor.go b/backend/runner/taskrun/data_export_executor.goindex f879f0549c..d28986f523 100644--- a/backend/runner/taskrun/data_export_executor.go+++ b/backend/runner/taskrun/data_export_executor.go@@ -74,7 +74,7 @@ func (exec *DataExportExecutor) RunOnce(ctx context.Context, _ context.Context,return true, nil, errors.Errorf("instance not found")}- sheet, err := exec.store.GetSheetFull(ctx, int(task.Payload.GetSheetId()))+ sheet, err := exec.store.GetSheetFull(ctx, task.Payload.GetSheetSha256())if err != nil {return true, nil, err}diff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.goindex 329d8eda92..2cc202f34e 100644--- a/backend/runner/taskrun/database_create_executor.go+++ b/backend/runner/taskrun/database_create_executor.go@@ -41,10 +41,9 @@ type DatabaseCreateExecutor struct {// RunOnce will run the database create task executor once.func (exec *DatabaseCreateExecutor) RunOnce(ctx context.Context, driverCtx context.Context, task *store.TaskMessage, _ int) (terminated bool, result *storepb.TaskRunResult, err error) {- sheetID := int(task.Payload.GetSheetId())- sheet, err := exec.store.GetSheetFull(ctx, sheetID)+ sheet, err := exec.store.GetSheetFull(ctx, task.Payload.GetSheetSha256())if err != nil {- return true, nil, errors.Wrapf(err, "failed to get sheet: %d", sheetID)+ return true, nil, errors.Wrapf(err, "failed to get sheet: %s", task.Payload.GetSheetSha256())}statement := sheet.Statementdiff --git a/backend/runner/taskrun/database_migrate_executor.go b/backend/runner/taskrun/database_migrate_executor.goindex 550da0470d..2bd4fd7137 100644--- a/backend/runner/taskrun/database_migrate_executor.go+++ b/backend/runner/taskrun/database_migrate_executor.go@@ -62,8 +62,7 @@ func (exec *DatabaseMigrateExecutor) RunOnce(ctx context.Context, driverCtx cont}func (exec *DatabaseMigrateExecutor) runMigrationWithPriorBackup(ctx context.Context, driverCtx context.Context, task *store.TaskMessage, taskRunUID int) (bool, *storepb.TaskRunResult, error) {- sheetID := int(task.Payload.GetSheetId())- sheet, err := exec.store.GetSheetFull(ctx, sheetID)+ sheet, err := exec.store.GetSheetFull(ctx, task.Payload.GetSheetSha256())if err != nil {return true, nil, err}@@ -125,7 +124,7 @@ func (exec *DatabaseMigrateExecutor) runMigrationWithPriorBackup(ctx context.Con}}- terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, statement, task.Payload.GetSchemaVersion(), &sheetID)+ terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, statement, task.Payload.GetSchemaVersion(), &sheet.Sha256)if result != nil {// Save prior backup detail to task run result.result.PriorBackupDetail = priorBackupDetail@@ -134,8 +133,7 @@ func (exec *DatabaseMigrateExecutor) runMigrationWithPriorBackup(ctx context.Con}func (exec *DatabaseMigrateExecutor) runGhostMigration(ctx context.Context, driverCtx context.Context, task *store.TaskMessage, taskRunUID int) (bool, *storepb.TaskRunResult, error) {- sheetID := int(task.Payload.GetSheetId())- sheet, err := exec.store.GetSheetFull(ctx, sheetID)+ sheet, err := exec.store.GetSheetFull(ctx, task.Payload.GetSheetSha256())if err != nil {return true, nil, err}@@ -231,7 +229,7 @@ func (exec *DatabaseMigrateExecutor) runGhostMigration(ctx context.Context, driv}}- return runMigrationWithFunc(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, statement, task.Payload.GetSchemaVersion(), &sheetID, execFunc)+ return runMigrationWithFunc(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, statement, task.Payload.GetSchemaVersion(), &sheet.Sha256, execFunc)}func (exec *DatabaseMigrateExecutor) shouldSkipBackupError(ctx context.Context, task *store.TaskMessage) (bool, error) {diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.goindex 5e064314a4..c6a4534515 100644--- a/backend/runner/taskrun/executor.go+++ b/backend/runner/taskrun/executor.go@@ -117,7 +117,7 @@ func getUseDatabaseOwner(ctx context.Context, stores *store.Store, instance *storeturn project.Setting.PostgresDatabaseTenantMode, nil}-func runMigration(ctx context.Context, driverCtx context.Context, store *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, syncer *schemasync.Syncer, profile *config.Profile, task *store.TaskMessage, taskRunUID int, statement string, schemaVersion string, sheetID *int) (terminated bool, result *storepb.TaskRunResult, err error) {+func runMigration(ctx context.Context, driverCtx context.Context, store *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, syncer *schemasync.Syncer, profile *config.Profile, task *store.TaskMessage, taskRunUID int, statement string, schemaVersion string, sheetID *string) (terminated bool, result *storepb.TaskRunResult, err error) {return runMigrationWithFunc(ctx, driverCtx, store, dbFactory, stateCfg, syncer, profile, task, taskRunUID, statement, schemaVersion, sheetID, nil /* default */)}@@ -133,7 +133,7 @@ func runMigrationWithFunc(taskRunUID int,statement string,schemaVersion string,- sheetID *int,+ sheetID *string,execFunc execFuncType,) (terminated bool, result *storepb.TaskRunResult, err error) {mc, err := getMigrationInfo(ctx, store, profile, syncer, task, schemaVersion, sheetID, taskRunUID, dbFactory)@@ -152,7 +152,7 @@ func runMigrationWithFunc(return postMigration(ctx, store, mc, skipped)}-func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, schemaVersion string, sheetID *int, taskRunUID int, dbFactory *dbfactory.DBFactory) (*migrateContext, error) {+func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, schemaVersion string, sheetID *string, taskRunUID int, dbFactory *dbfactory.DBFactory) (*migrateContext, error) {instance, err := stores.GetInstance(ctx, &store.FindInstanceMessage{ResourceID: &task.InstanceID})if err != nil {return nil, err@@ -203,7 +203,7 @@ func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.return nil, errors.Wrapf(err, "failed to get sheet")}mc.sheet = sheet- mc.sheetName = common.FormatSheet(pipeline.ProjectID, sheet.UID)+ mc.sheetName = common.FormatSheet(pipeline.ProjectID, sheet.Sha256)}if isChangeDatabaseTask(task) {@@ -441,7 +441,7 @@ func beginMigration(ctx context.Context, stores *store.Store, mc *migrateContextPayload: &storepb.ChangelogPayload{TaskRun: mc.taskRunName,Revision: 0,- Sheet: mc.sheetName,+ SheetSha256: mc.sheet.Sha256,Version: mc.version,Type: changelogType,GitCommit: mc.profile.GitCommit,@@ -482,7 +482,6 @@ func endMigration(ctx context.Context, storeInstance *store.Store, mc *migrateCoPayload: &storepb.RevisionPayload{Release: mc.release.release,File: mc.release.file,- Sheet: "",SheetSha256: "",TaskRun: mc.taskRunName,Type: storepb.SchemaChangeType_VERSIONED,@@ -492,8 +491,7 @@ func endMigration(ctx context.Context, storeInstance *store.Store, mc *migrateCor.Payload.Type = storepb.SchemaChangeType_DECLARATIVE}if mc.sheet != nil {- r.Payload.Sheet = mc.sheetName- r.Payload.SheetSha256 = mc.sheet.GetSha256Hex()+ r.Payload.SheetSha256 = mc.sheet.Sha256}revision, err := storeInstance.CreateRevision(ctx, r)diff --git a/backend/runner/taskrun/schema_update_sdl_executor.go b/backend/runner/taskrun/schema_update_sdl_executor.goindex 7164bd5367..95fd52f75c 100644--- a/backend/runner/taskrun/schema_update_sdl_executor.go+++ b/backend/runner/taskrun/schema_update_sdl_executor.go@@ -51,8 +51,7 @@ func (exec *SchemaDeclareExecutor) RunOnce(ctx context.Context, driverCtx contexreturn true, nil, err}- sheetID := int(task.Payload.GetSheetId())- sheet, err := exec.store.GetSheetFull(ctx, sheetID)+ sheet, err := exec.store.GetSheetFull(ctx, task.Payload.GetSheetSha256())if err != nil {return true, nil, err}@@ -75,7 +74,7 @@ func (exec *SchemaDeclareExecutor) RunOnce(ctx context.Context, driverCtx contexreturn nil}- return runMigrationWithFunc(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, sheetContent, task.Payload.GetSchemaVersion(), &sheetID, execFunc)+ return runMigrationWithFunc(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, sheetContent, task.Payload.GetSchemaVersion(), &sheet.Sha256, execFunc)}func diff(ctx context.Context, s *store.Store, instance *store.InstanceMessage, database *store.DatabaseMessage, sheetContent string) (string, error) {@@ -156,19 +155,13 @@ func getPreviousSuccessfulSDLAndSchema(ctx context.Context, s *store.Store, inst// Extract the sheet ID from the changelog payloadvar previousUserSDLText string- if mostRecentChangelog.Payload != nil && mostRecentChangelog.Payload.Sheet != "" {- sheetResource := mostRecentChangelog.Payload.Sheet-- // Extract sheet ID from resource string format: "projects/{project}/sheets/{sheet}"- _, sheetID, err := common.GetProjectResourceIDSheetUID(sheetResource)- if err != nil {- return "", nil, errors.Wrapf(err, "failed to extract sheet ID from resource %s", sheetResource)- }+ if mostRecentChangelog.Payload != nil && mostRecentChangelog.Payload.SheetSha256 != "" {+ sheetSha256 := mostRecentChangelog.Payload.SheetSha256// Get the sheet content (original SDL text)- sheet, err := s.GetSheetFull(ctx, sheetID)+ sheet, err := s.GetSheetFull(ctx, sheetSha256)if err != nil {- return "", nil, errors.Wrapf(err, "failed to get sheet statement for previous SDL changelog sheet ID %d", sheetID)+ return "", nil, errors.Wrapf(err, "failed to get sheet statement for previous SDL changelog sheet %s", sheetSha256)}previousUserSDLText = sheet.Statement}diff --git a/backend/runner/taskrun/schema_update_sdl_executor_test.go b/backend/runner/taskrun/schema_update_sdl_executor_test.goindex 0b8e53d5d4..e1fd1b5022 100644--- a/backend/runner/taskrun/schema_update_sdl_executor_test.go+++ b/backend/runner/taskrun/schema_update_sdl_executor_test.go@@ -11,46 +11,46 @@ import (func TestSheetResourceParsing(t *testing.T) {// Test that we can use the common function correctlytests := []struct {- name string- resource string- expectedID int- expectError bool+ name string+ resource string+ expectedSha256 string+ expectError bool}{{- name: "valid_resource",- resource: "projects/123/sheets/456",- expectedID: 456,- expectError: false,+ name: "valid_resource",+ resource: "projects/123/sheets/abc123",+ expectedSha256: "abc123",+ expectError: false,},{- name: "another_valid_resource",- resource: "projects/myproject/sheets/789",- expectedID: 789,- expectError: false,+ name: "another_valid_resource",+ resource: "projects/myproject/sheets/def456",+ expectedSha256: "def456",+ expectError: false,},{- name: "invalid_format_missing_sheets",- resource: "projects/123/documents/456",- expectedID: 0,- expectError: true,+ name: "invalid_format_missing_sheets",+ resource: "projects/123/documents/456",+ expectedSha256: "",+ expectError: true,},{- name: "invalid_format_wrong_structure",- resource: "projects/123",- expectedID: 0,- expectError: true,+ name: "invalid_format_wrong_structure",+ resource: "projects/123",+ expectedSha256: "",+ expectError: true,},}for _, tt := range tests {t.Run(tt.name, func(t *testing.T) {- _, sheetID, err := common.GetProjectResourceIDSheetUID(tt.resource)+ _, sheetSha256, err := common.GetProjectResourceIDSheetSha256(tt.resource)if tt.expectError {require.Error(t, err)} else {require.NoError(t, err)- require.Equal(t, tt.expectedID, sheetID)+ require.Equal(t, tt.expectedSha256, sheetSha256)}})}diff --git a/backend/store/pipeline.go b/backend/store/pipeline.goindex c9799b88e6..f6ef1a9b05 100644--- a/backend/store/pipeline.go+++ b/backend/store/pipeline.go@@ -80,14 +80,14 @@ func (s *Store) CreatePipelineAIO(ctx context.Context, planUID int64, pipeline *type taskKey struct {instance stringdatabase string- sheet int+ sheet string}createdTasks := map[taskKey]struct{}{}for _, task := range existingTasks {k := taskKey{instance: task.InstanceID,- sheet: int(task.Payload.GetSheetId()),+ sheet: task.Payload.GetSheetSha256(),}if task.DatabaseName != nil {k.database = *task.DatabaseName@@ -100,7 +100,7 @@ func (s *Store) CreatePipelineAIO(ctx context.Context, planUID int64, pipeline *for _, taskCreate := range pipeline.Tasks {k := taskKey{instance: taskCreate.InstanceID,- sheet: int(taskCreate.Payload.GetSheetId()),+ sheet: taskCreate.Payload.GetSheetSha256(),}if taskCreate.DatabaseName != nil {k.database = *taskCreate.DatabaseNamediff --git a/backend/store/sheet.go b/backend/store/sheet.goindex e7a63207ee..fa6461c364 100644--- a/backend/store/sheet.go+++ b/backend/store/sheet.go@@ -6,7 +6,6 @@ import ("database/sql""encoding/hex""fmt"- "time""github.com/pkg/errors"@@ -16,79 +15,61 @@ import (// SheetMessage is the message for a sheet.type SheetMessage struct {- ProjectID string-- Creator string-- Title string+ // SHA256 hash of the statement (hex-encoded)+ Sha256 string+ // SQL statement contentStatement string-- // Sha256 is the Sha256 hash of the statement.- Sha256 []byte-- // Output only fields- UID int- Size int64- CreatedAt time.Time-}--func (s *SheetMessage) GetSha256Hex() string {- return hex.EncodeToString(s.Sha256)+ // Size of the statement in bytes+ Size int64}-// GetSheetMetadata gets a sheet with truncated statement (max 2MB).-// Use this when you need to check sheet.Size or other metadata before processing.+// GetSheetMetadata gets a sheet by SHA256 hash with truncated statement (max 2MB).// Statement field will be truncated to MaxSheetSize (2MB).-func (s *Store) GetSheetMetadata(ctx context.Context, id int) (*SheetMessage, error) {- if v, ok := s.sheetMetadataCache.Get(id); ok && s.enableCache {+// Results are cached by SHA256 hex string.+func (s *Store) GetSheetMetadata(ctx context.Context, sha256Hex string) (*SheetMessage, error) {+ if v, ok := s.sheetMetadataCache.Get(sha256Hex); ok && s.enableCache {return v, nil}- sheet, err := s.getSheet(ctx, id, false)+ sheet, err := s.getSheet(ctx, sha256Hex, false)if err != nil {return nil, err}- s.sheetMetadataCache.Add(id, sheet)+ s.sheetMetadataCache.Add(sha256Hex, sheet)return sheet, nil}-// GetSheetFull gets a sheet with the complete statement.-// Use this when you need the full statement for execution or processing.+// GetSheetFull gets a sheet by SHA256 hash with the complete statement.// Statement field contains the complete content regardless of size.-func (s *Store) GetSheetFull(ctx context.Context, id int) (*SheetMessage, error) {- if v, ok := s.sheetFullCache.Get(id); ok && s.enableCache {+// Results are cached by SHA256 hex string.+func (s *Store) GetSheetFull(ctx context.Context, sha256Hex string) (*SheetMessage, error) {+ if v, ok := s.sheetFullCache.Get(sha256Hex); ok && s.enableCache {return v, nil}- sheet, err := s.getSheet(ctx, id, true)+ sheet, err := s.getSheet(ctx, sha256Hex, true)if err != nil {return nil, err}- s.sheetFullCache.Add(id, sheet)+ s.sheetFullCache.Add(sha256Hex, sheet)return sheet, nil}-// getSheet is the internal helper for fetching a single sheet by ID.-func (s *Store) getSheet(ctx context.Context, id int, loadFull bool) (*SheetMessage, error) {- statementField := fmt.Sprintf("LEFT(sheet_blob.content, %d)", common.MaxSheetSize)+// getSheet is the internal helper for fetching a single sheet by SHA256.+func (s *Store) getSheet(ctx context.Context, sha256Hex string, loadFull bool) (*SheetMessage, error) {+ statementField := fmt.Sprintf("LEFT(content, %d)", common.MaxSheetSize)if loadFull {- statementField = "sheet_blob.content"+ statementField = "content"}q := qb.Q().Space(fmt.Sprintf(`SELECT- sheet.id,- sheet.creator,- sheet.created_at,- sheet.project,%s,- sheet.sha256,- OCTET_LENGTH(sheet_blob.content)- FROM sheet- LEFT JOIN sheet_blob ON sheet.sha256 = sheet_blob.sha256- WHERE sheet.id = ?`, statementField), id)+ OCTET_LENGTH(content)+ FROM sheet_blob+ WHERE sha256 = decode(?, 'hex')`, statementField), sha256Hex)query, args, err := q.ToSQL()if err != nil {@@ -109,14 +90,11 @@ func (s *Store) getSheet(ctx context.Context, id int, loadFull bool) (*SheetMessvar sheet *SheetMessageif rows.Next() {- sheet = &SheetMessage{}+ sheet = &SheetMessage{+ Sha256: sha256Hex,+ }if err := rows.Scan(- &sheet.UID,- &sheet.Creator,- &sheet.CreatedAt,- &sheet.ProjectID,&sheet.Statement,- &sheet.Sha256,&sheet.Size,); err != nil {return nil, err@@ -131,88 +109,27 @@ func (s *Store) getSheet(ctx context.Context, id int, loadFull bool) (*SheetMess}if sheet == nil {- return nil, errors.Errorf("sheet not found with id %d", id)+ return nil, errors.Errorf("sheet not found with sha256 %s", sha256Hex)}return sheet, nil}-// CreateSheets creates new sheets.-// You should not use this function directly to create sheets.-// Use CreateSheets in component/sheet instead.-func (s *Store) CreateSheets(ctx context.Context, projectID string, _ string, creates ...*SheetMessage) ([]*SheetMessage, error) {- var names []string+// CreateSheets creates sheet blobs using content-addressed storage.+// Each sheet is identified by the SHA256 hash of its statement.+// Duplicate statements share the same blob (ON CONFLICT DO NOTHING).+func (s *Store) CreateSheets(ctx context.Context, creates ...*SheetMessage) ([]*SheetMessage, error) {var statements []stringvar sha256s [][]bytefor _, c := range creates {- c.ProjectID = projectID- c.Creator = SystemBotUser.Email- names = append(names, "")statements = append(statements, c.Statement)h := sha256.Sum256([]byte(c.Statement))- c.Sha256 = h[:]- sha256s = append(sha256s, c.Sha256)- }-- if err := s.batchCreateSheetBlob(ctx, sha256s, statements); err != nil {- return nil, errors.Wrapf(err, "failed to create sheet blobs")+ c.Sha256 = hex.EncodeToString(h[:])+ sha256s = append(sha256s, h[:])+ c.Size = int64(len(c.Statement))}- q := qb.Q().Space(`- INSERT INTO sheet (- creator,- project,- name,- sha256- ) SELECT- ?,- ?,- unnest(CAST(? AS TEXT[])),- unnest(CAST(? AS BYTEA[]))- RETURNING id, created_at- `, SystemBotUser.Email, projectID, names, sha256s)-- query, args, err := q.ToSQL()- if err != nil {- return nil, errors.Wrapf(err, "failed to build sql")- }-- tx, err := s.GetDB().BeginTx(ctx, nil)- if err != nil {- return nil, errors.Wrapf(err, "failed to begin tx")- }- defer tx.Rollback()-- rows, err := tx.QueryContext(ctx, query, args...)- if err != nil {- return nil, errors.Wrapf(err, "failed to query")- }- defer rows.Close()-- for i := 0; rows.Next(); i++ {- if err := rows.Scan(- &creates[i].UID,- &creates[i].CreatedAt,- ); err != nil {- return nil, errors.Wrapf(err, "failed to scan")- }-- creates[i].Size = int64(len(creates[i].Statement))- }-- if err := rows.Err(); err != nil {- return nil, errors.Wrapf(err, "rows err")- }-- if err := tx.Commit(); err != nil {- return nil, errors.Wrapf(err, "failed to commit tx")- }-- return creates, nil-}--func (s *Store) batchCreateSheetBlob(ctx context.Context, sha256s [][]byte, contents []string) error {q := qb.Q().Space(`INSERT INTO sheet_blob (sha256,@@ -221,16 +138,16 @@ func (s *Store) batchCreateSheetBlob(ctx context.Context, sha256s [][]byte, contunnest(CAST(? AS BYTEA[])),unnest(CAST(? AS TEXT[]))ON CONFLICT DO NOTHING- `, sha256s, contents)+ `, sha256s, statements)query, args, err := q.ToSQL()if err != nil {- return errors.Wrapf(err, "failed to build sql")+ return nil, errors.Wrapf(err, "failed to build sql")}if _, err := s.GetDB().ExecContext(ctx, query, args...); err != nil {- return errors.Wrapf(err, "failed to exec")+ return nil, errors.Wrapf(err, "failed to exec")}- return nil+ return creates, nil}diff --git a/backend/store/store.go b/backend/store/store.goindex 8a6b4c9020..1aa883088b 100644--- a/backend/store/store.go+++ b/backend/store/store.go@@ -27,10 +27,10 @@ type Store struct {settingCache *lru.Cache[storepb.SettingName, *SettingMessage]rolesCache *lru.Cache[string, *RoleMessage]groupCache *lru.Cache[string, *GroupMessage]- sheetMetadataCache *lru.Cache[int, *SheetMessage]+ sheetMetadataCache *lru.Cache[string, *SheetMessage]// Large objects.- sheetFullCache *lru.Cache[int, *SheetMessage]+ sheetFullCache *lru.Cache[string, *SheetMessage]dbMetadataCache *lru.Cache[string, *model.DatabaseMetadata]}@@ -65,11 +65,11 @@ func New(ctx context.Context, pgURL string, enableCache bool) (*Store, error) {if err != nil {return nil, err}- sheetMetadataCache, err := lru.New[int, *SheetMessage](64)+ sheetMetadataCache, err := lru.New[string, *SheetMessage](64)if err != nil {return nil, err}- sheetFullCache, err := lru.New[int, *SheetMessage](10)+ sheetFullCache, err := lru.New[string, *SheetMessage](10)if err != nil {return nil, err}diff --git a/backend/store/task.go b/backend/store/task.goindex a11a1d0e63..9938babd8f 100644--- a/backend/store/task.go+++ b/backend/store/task.go@@ -78,7 +78,7 @@ type TaskPatch struct {DatabaseName *stringType *storepb.Task_Type- SheetID *int+ SheetSha256 *stringSchemaVersion *stringExportFormat *storepb.ExportFormatExportPassword *string@@ -400,8 +400,8 @@ func (s *Store) UpdateTask(ctx context.Context, patch *TaskPatch) (*TaskMessage,}payloadParts := qb.Q()- if v := patch.SheetID; v != nil {- payloadParts.Join(" || ", "jsonb_build_object('sheetId', ?::INT)", *v)+ if v := patch.SheetSha256; v != nil {+ payloadParts.Join(" || ", "jsonb_build_object('sheetSha256', ?::TEXT)", *v)}if v := patch.SchemaVersion; v != nil {payloadParts.Join(" || ", "jsonb_build_object('schemaVersion', ?::TEXT)", *v)diff --git a/backend/store/task_run.go b/backend/store/task_run.goindex 28dcd37e94..7c26237df7 100644--- a/backend/store/task_run.go+++ b/backend/store/task_run.go@@ -21,7 +21,7 @@ type TaskRunMessage struct {Code common.CodeResult stringResultProto *storepb.TaskRunResult- SheetUID *int+ SheetSha256 *string// Output only.ID int@@ -70,7 +70,7 @@ func (s *Store) ListTaskRuns(ctx context.Context, find *FindTaskRunMessage) ([]*task_run.run_at,task_run.code,task_run.result,- task_run.sheet_id,+ encode(task_run.sheet_sha256, 'hex'),task.pipeline_id,task.environment,project.resource_id@@ -122,6 +122,7 @@ func (s *Store) ListTaskRuns(ctx context.Context, find *FindTaskRunMessage) ([]*var taskRun TaskRunMessagevar startedAt, runAt sql.NullTimevar statusString string+ var sheetSha256 sql.NullStringif err := rows.Scan(&taskRun.ID,&taskRun.CreatorEmail,@@ -133,13 +134,16 @@ func (s *Store) ListTaskRuns(ctx context.Context, find *FindTaskRunMessage) ([]*&runAt,&taskRun.Code,&taskRun.Result,- &taskRun.SheetUID,+ &sheetSha256,&taskRun.PipelineUID,&taskRun.Environment,&taskRun.ProjectID,); err != nil {return nil, err}+ if sheetSha256.Valid {+ taskRun.SheetSha256 = &sheetSha256.String+ }if statusValue, ok := storepb.TaskRun_Status_value[statusString]; ok {taskRun.Status = storepb.TaskRun_Status(statusValue)} else {@@ -249,11 +253,11 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creator string, creat}var taskUIDs []int- var sheetUIDs []*int+ var sheetSha256s []*stringvar runAts []*time.Timefor _, create := range creates {taskUIDs = append(taskUIDs, create.TaskUID)- sheetUIDs = append(sheetUIDs, create.SheetUID)+ sheetSha256s = append(sheetSha256s, create.SheetSha256)runAts = append(runAts, create.RunAt)}@@ -266,7 +270,7 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creator string, creatINSERT INTO task_run (creator,task_id,- sheet_id,+ sheet_sha256,run_at,attempt,status@@ -274,15 +278,21 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creator string, creatSELECT?,tasks.task_id,- tasks.sheet_id,+ tasks.sheet_sha256,tasks.run_at,COALESCE((SELECT MAX(attempt) + 1 FROM task_run WHERE task_run.task_id = tasks.task_id), 0) as attempt,?FROM (SELECTunnest(CAST(? AS INTEGER[])) AS task_id,- unnest(CAST(? AS INTEGER[])) AS sheet_id,+ unnest(CAST(? AS TEXT[])) AS sheet_sha256_hex,unnest(CAST(? AS TIMESTAMPTZ[])) AS run_at+ ) tasks_raw+ CROSS JOIN LATERAL (+ SELECT+ tasks_raw.task_id,+ CASE WHEN tasks_raw.sheet_sha256_hex IS NOT NULL THEN decode(tasks_raw.sheet_sha256_hex, 'hex') ELSE NULL END AS sheet_sha256,+ tasks_raw.run_at) tasksWHERE NOT EXISTS (SELECT 1 FROM task_run@@ -290,7 +300,7 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creator string, creatAND task_run.status IN (?, ?, ?))ON CONFLICT (task_id, attempt) DO NOTHING- `, creator, storepb.TaskRun_PENDING.String(), taskUIDs, sheetUIDs, runAts,+ `, creator, storepb.TaskRun_PENDING.String(), taskUIDs, sheetSha256s, runAts,storepb.TaskRun_PENDING.String(), storepb.TaskRun_RUNNING.String(), storepb.TaskRun_DONE.String())query, args, err := q.ToSQL()diff --git a/docs/plans/2025-12-19-sheet-content-addressed-storage-design.md b/docs/plans/2025-12-19-sheet-content-addressed-storage-design.mdnew file mode 100644index 0000000000..8195969862--- /dev/null+++ b/docs/plans/2025-12-19-sheet-content-addressed-storage-design.md@@ -0,0 +1,259 @@+# Content-Addressed Storage for Sheets++## Overview++Migrate sheet storage from ID-based to content-addressed (SHA256-based) storage. The `store.SheetMessage` will reference `sheet_blob` table directly instead of the `sheet` table. The `sheet` table will be dropped entirely.++## Goals++- Use SHA256 hash as the primary identifier for sheets+- Share sheet blobs across projects (immutable, content-addressed storage)+- Simplify data model by removing sheet metadata (creator, project, title)+- Change v1 API resource names from `projects/{project}/sheets/{id}` to `projects/{project}/sheets/{sha256}`++## Non-Goals++- Change authorization model (already project-scoped, no changes needed)+- Gradual migration or backward compatibility (direct cutover)++## Data Model Changes++### SheetMessage Struct++**Before:**+```go+type SheetMessage struct {+ ProjectID string+ Creator string+ Title string+ Statement string+ Sha256 []byte+ UID int+ Size int64+ CreatedAt time.Time+}+```++**After:**+```go+type SheetMessage struct {+ // SHA256 hash of the statement (hex-encoded)+ Sha256 string+ // SQL statement content+ Statement string+ // Size of the statement in bytes+ Size int64+}+```++### Database Schema Changes++**sheet_blob table** - no changes:+```sql+CREATE TABLE sheet_blob (+ sha256 bytea NOT NULL PRIMARY KEY,+ content text NOT NULL+);+```++**task_run table** - replace integer foreign key:+```sql+-- Before:+CREATE TABLE task_run (+ ...+ sheet_id integer REFERENCES sheet(id),+ ...+);++-- After:+CREATE TABLE task_run (+ ...+ sheet_sha256 bytea REFERENCES sheet_blob(sha256),+ ...+);+```++**sheet table** - will be dropped entirely after migration.++### Proto Changes++**proto/store/store/task.proto:**+```protobuf+message Task {+ // Before:+ // int32 sheet_id = 4;++ // After:+ // SHA256 hash of the sheet content (hex-encoded)+ string sheet_sha256 = 4;+}+```++The proto field stores the hex-encoded SHA256 string. When exposed via v1 API, it gets embedded in the full resource name `projects/{project}/sheets/{sha256}`.++## Migration Strategy++### Direct Cutover++All changes happen in a single migration. No intermediate state.++**Migration SQL:**++```sql+-- 1. Add new column with sha256 reference+ALTER TABLE task_run ADD COLUMN sheet_sha256 bytea REFERENCES sheet_blob(sha256);++-- 2. Backfill task_run.sheet_sha256 from sheet table+UPDATE task_run tr+SET sheet_sha256 = s.sha256+FROM sheet s+WHERE tr.sheet_id = s.id;++-- 3. Backfill task.payload JSONB (Task proto)+-- Converts sheetId (int) to sheetSha256 (hex string)+UPDATE task t+SET payload = jsonb_set(+ payload - 'sheetId',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE (t.payload->>'sheetId')::int = s.id+AND t.payload ? 'sheetId';++-- 4. Drop old column+ALTER TABLE task_run DROP COLUMN sheet_id;++-- 5. Drop sheet table entirely+DROP TABLE sheet;+```++### Code Deployment++All code changes deploy atomically with the database migration:++- Update proto definitions (regenerate with `buf generate`)+- Update `store.SheetMessage` struct+- Update all store methods that query/create sheets+- Update all API handlers to use sha256-based resource names+- Update frontend to use new resource name format++No feature flags or compatibility layers needed.++## Code Changes++### backend/store/sheet.go++**SheetMessage struct:**+```go+type SheetMessage struct {+ Sha256 string+ Statement string+ Size int64+}+// Remove GetSha256Hex() method - Sha256 is already hex string+```++**GetSheetMetadata / GetSheetFull:**+```go+// Before:+func (s *Store) GetSheetMetadata(ctx context.Context, id int) (*SheetMessage, error)+func (s *Store) GetSheetFull(ctx context.Context, id int) (*SheetMessage, error)++// After:+func (s *Store) GetSheetMetadata(ctx context.Context, sha256Hex string) (*SheetMessage, error)+func (s *Store) GetSheetFull(ctx context.Context, sha256Hex string) (*SheetMessage, error)+```++**Query changes:**+```go+// Before:+// SELECT ... FROM sheet+// LEFT JOIN sheet_blob ON sheet.sha256 = sheet_blob.sha256+// WHERE sheet.id = ?++// After:+// SELECT ... FROM sheet_blob+// WHERE sha256 = decode(?, 'hex')+```++**CreateSheets:**+```go+// No longer creates rows in sheet table+// Just calls batchCreateSheetBlob+// Returns SheetMessage with sha256, statement, size+func (s *Store) CreateSheets(ctx context.Context, creates ...*SheetMessage) ([]*SheetMessage, error)+```++### Proto Changes++Run after updating task.proto:+```bash+cd proto && buf generate+```++### Callers++Any code calling `store.GetSheetMetadata(ctx, sheetID)` changes to pass sha256 hex string instead of integer ID. Similarly for creating/updating tasks that reference sheets.++## API Changes++### Resource Name Format++**Before:**+```+projects/{project}/sheets/{id}+```+Example: `projects/my-project/sheets/123`++**After:**+```+projects/{project}/sheets/{sha256}+```+Example: `projects/my-project/sheets/a1b2c3d4e5f67890abcdef...`++### Authorization++No change. Authorization works the same way:+- User must have IAM permission to access the project+- Sheet retrieval is project-scoped via the resource name+- No verification that the project actually "owns" the sheet++### Converting Between Store and API Formats++**Store → API:**+```go+// Store has: sheet_sha256 = "a1b2c3d4..."+// API returns: "projects/my-project/sheets/a1b2c3d4..."+sheetResourceName := fmt.Sprintf("projects/%s/sheets/%s", project, sheetSha256)+```++**API → Store:**+```go+// Parse resource name to extract sha256+// Call store.GetSheetMetadata(ctx, sha256Hex)+```++### Client Impact++Clients see sheet IDs change from integers (`123`) to SHA256 hashes (`a1b2c3d4...`). The API endpoints and request/response structure remain the same.++## Benefits++- **Deduplication**: Same SQL content stored once, referenced by multiple tasks/projects+- **Immutability**: SHA256-based addressing guarantees content integrity+- **Simplicity**: Removes unnecessary metadata, cleaner data model+- **Scalability**: Content-addressed storage scales better than relational references++## Risks++- **Breaking change**: Existing sheet IDs become invalid+- **Client compatibility**: All API clients must handle sha256-based IDs+- **Migration complexity**: JSONB backfill must handle all edge cases correctly++## Testing++- Unit tests for store methods with sha256-based lookups+- Integration tests for migration SQL (verify data integrity)+- API tests for new resource name format+- Frontend tests for displaying sha256-based sheet referencesdiff --git a/docs/plans/2025-12-19-sheet-content-addressed-storage.md b/docs/plans/2025-12-19-sheet-content-addressed-storage.mdnew file mode 100644index 0000000000..530ea84e5b--- /dev/null+++ b/docs/plans/2025-12-19-sheet-content-addressed-storage.md@@ -0,0 +1,1086 @@+# Sheet Content-Addressed Storage Implementation Plan++> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.++**Goal:** Migrate sheet storage from ID-based to SHA256-based content addressing, pointing store.SheetMessage directly to sheet_blob table.++**Architecture:** Replace sheet table with direct sheet_blob references. Use SHA256 hash (hex string) as identifier throughout the codebase. Update all foreign keys and proto fields from int32 to string (hex sha256). Create migration to backfill existing data.++**Tech Stack:** Go, Protocol Buffers, PostgreSQL, Bytebase store layer++---++## Task 1: Update Proto Definitions++**Files:**+- Modify: `proto/store/store/task.proto:31`++**Step 1: Update Task proto to use sheet_sha256**++Edit `proto/store/store/task.proto`:++```protobuf+// Change line 31 from:+// int32 sheet_id = 4;++// To:+// The SHA256 hash of the sheet content (hex-encoded).+string sheet_sha256 = 4;+```++**Step 2: Format proto file**++Run: `buf format -w proto`+Expected: File formatted successfully++**Step 3: Lint proto file**++Run: `buf lint proto`+Expected: No lint errors++**Step 4: Generate Go code from proto**++Run: `cd proto && buf generate`+Expected: Generated files updated in backend/generated-go/++**Step 5: Commit proto changes**++```bash+git add proto/store/store/task.proto backend/generated-go/+git commit -m "feat: change Task.sheet_id to sheet_sha256 string++Update proto definition to use SHA256 hash instead of integer ID+for sheet references.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 2: Update SheetMessage Struct++**Files:**+- Modify: `backend/store/sheet.go:17-37`++**Step 1: Update SheetMessage struct**++Edit `backend/store/sheet.go`, replace the struct definition:++```go+// SheetMessage is the message for a sheet.+type SheetMessage struct {+ // SHA256 hash of the statement (hex-encoded)+ Sha256 string+ // SQL statement content+ Statement string+ // Size of the statement in bytes+ Size int64+}+```++Remove the `GetSha256Hex()` method (lines 35-37) since Sha256 is already a hex string.++**Step 2: Run Go format**++Run: `gofmt -w backend/store/sheet.go`+Expected: File formatted++**Step 3: Verify it compiles (will fail, expected)**++Run: `go build ./backend/store/...`+Expected: Compilation errors (methods still use old signature)++**Step 4: Commit struct changes**++```bash+git add backend/store/sheet.go+git commit -m "refactor: simplify SheetMessage to use hex SHA256++Remove ProjectID, Creator, Title, UID, CreatedAt fields.+Change Sha256 from []byte to string (hex-encoded).++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 3: Update GetSheetMetadata Method++**Files:**+- Modify: `backend/store/sheet.go:39-54`++**Step 1: Update GetSheetMetadata signature and implementation**++Edit `backend/store/sheet.go`:++```go+// GetSheetMetadata gets a sheet with truncated statement (max 2MB).+// Use this when you need to check sheet.Size or other metadata before processing.+// Statement field will be truncated to MaxSheetSize (2MB).+func (s *Store) GetSheetMetadata(ctx context.Context, sha256Hex string) (*SheetMessage, error) {+ if v, ok := s.sheetMetadataCache.Get(sha256Hex); ok && s.enableCache {+ return v, nil+ }++ sheet, err := s.getSheet(ctx, sha256Hex, false)+ if err != nil {+ return nil, err+ }++ s.sheetMetadataCache.Add(sha256Hex, sheet)+ return sheet, nil+}+```++**Step 2: Update GetSheetFull method**++Edit `backend/store/sheet.go`:++```go+// GetSheetFull gets a sheet with the complete statement.+// Use this when you need the full statement for execution or processing.+// Statement field contains the complete content regardless of size.+func (s *Store) GetSheetFull(ctx context.Context, sha256Hex string) (*SheetMessage, error) {+ if v, ok := s.sheetFullCache.Get(sha256Hex); ok && s.enableCache {+ return v, nil+ }++ sheet, err := s.getSheet(ctx, sha256Hex, true)+ if err != nil {+ return nil, err+ }++ s.sheetFullCache.Add(sha256Hex, sheet)+ return sheet, nil+}+```++**Step 3: Update getSheet helper method**++Edit `backend/store/sheet.go`:++```go+// getSheet is the internal helper for fetching a single sheet by SHA256.+func (s *Store) getSheet(ctx context.Context, sha256Hex string, loadFull bool) (*SheetMessage, error) {+ statementField := fmt.Sprintf("LEFT(content, %d)", common.MaxSheetSize)+ if loadFull {+ statementField = "content"+ }++ q := qb.Q().Space(fmt.Sprintf(`+ SELECT+ %s,+ OCTET_LENGTH(content)+ FROM sheet_blob+ WHERE sha256 = decode(?, 'hex')`, statementField), sha256Hex)++ query, args, err := q.ToSQL()+ if err != nil {+ return nil, errors.Wrapf(err, "failed to build sql")+ }++ tx, err := s.GetDB().BeginTx(ctx, &sql.TxOptions{ReadOnly: true})+ if err != nil {+ return nil, err+ }+ defer tx.Rollback()++ rows, err := tx.QueryContext(ctx, query, args...)+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ var sheet *SheetMessage+ if rows.Next() {+ sheet = &SheetMessage{+ Sha256: sha256Hex,+ }+ if err := rows.Scan(+ &sheet.Statement,+ &sheet.Size,+ ); err != nil {+ return nil, err+ }+ }++ if err := rows.Err(); err != nil {+ return nil, err+ }+ if err := tx.Commit(); err != nil {+ return nil, err+ }++ if sheet == nil {+ return nil, errors.Errorf("sheet not found with sha256 %s", sha256Hex)+ }++ return sheet, nil+}+```++**Step 4: Run Go format**++Run: `gofmt -w backend/store/sheet.go`+Expected: File formatted++**Step 5: Commit changes**++```bash+git add backend/store/sheet.go+git commit -m "refactor: update sheet get methods to use SHA256++Query sheet_blob directly by SHA256 instead of joining with sheet table.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 4: Update CreateSheets Method++**Files:**+- Modify: `backend/store/sheet.go:140-213`++**Step 1: Update CreateSheets signature and implementation**++Edit `backend/store/sheet.go`:++```go+// CreateSheets creates new sheets.+// You should not use this function directly to create sheets.+// Use CreateSheets in component/sheet instead.+func (s *Store) CreateSheets(ctx context.Context, creates ...*SheetMessage) ([]*SheetMessage, error) {+ var statements []string+ var sha256s [][]byte++ for _, c := range creates {+ statements = append(statements, c.Statement)+ h := sha256.Sum256([]byte(c.Statement))+ c.Sha256 = hex.EncodeToString(h[:])+ sha256s = append(sha256s, h[:])+ c.Size = int64(len(c.Statement))+ }++ if err := s.batchCreateSheetBlob(ctx, sha256s, statements); err != nil {+ return nil, errors.Wrapf(err, "failed to create sheet blobs")+ }++ return creates, nil+}+```++**Step 2: Run Go format**++Run: `gofmt -w backend/store/sheet.go`+Expected: File formatted++**Step 3: Commit changes**++```bash+git add backend/store/sheet.go+git commit -m "refactor: simplify CreateSheets to only create blobs++Remove sheet table insertion, only create sheet_blob entries.+Calculate and return SHA256 hex strings.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 5: Update Store Cache Types++**Files:**+- Modify: `backend/store/store.go` (find sheetMetadataCache and sheetFullCache)++**Step 1: Find cache definitions**++Run: `grep -n "sheetMetadataCache\|sheetFullCache" backend/store/store.go`+Expected: Line numbers for cache field definitions++**Step 2: Update cache key type from int to string**++Find the Store struct and update the cache fields:++```go+// Before:+// sheetMetadataCache *cache.Cache[int, *SheetMessage]+// sheetFullCache *cache.Cache[int, *SheetMessage]++// After:+sheetMetadataCache *cache.Cache[string, *SheetMessage]+sheetFullCache *cache.Cache[string, *SheetMessage]+```++**Step 3: Find cache initialization**++Run: `grep -n "NewCache.*SheetMessage" backend/store/store.go`+Expected: Cache initialization code++Update cache initialization from:+```go+// Before:+// cache.NewCache[int, *SheetMessage](...)++// After:+cache.NewCache[string, *SheetMessage](...)+```++**Step 4: Run Go format**++Run: `gofmt -w backend/store/store.go`+Expected: File formatted++**Step 5: Verify it compiles**++Run: `go build ./backend/store/...`+Expected: SUCCESS (store package should compile now)++**Step 6: Commit changes**++```bash+git add backend/store/store.go+git commit -m "refactor: update sheet cache to use string keys++Change cache key type from int to string (SHA256 hex).++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 6: Create Database Migration++**Files:**+- Create: `backend/migrator/migration/4.0/0000##sheet_content_addressed.sql`+- Modify: `backend/migrator/migration/LATEST.sql`++**Step 1: Create migration directory**++Run: `mkdir -p backend/migrator/migration/4.0`+Expected: Directory created++**Step 2: Create migration SQL file**++Create `backend/migrator/migration/4.0/0000##sheet_content_addressed.sql`:++```sql+-- Add new column with sha256 reference to task_run+ALTER TABLE task_run ADD COLUMN sheet_sha256 bytea REFERENCES sheet_blob(sha256);++-- Backfill task_run.sheet_sha256 from sheet table+UPDATE task_run tr+SET sheet_sha256 = s.sha256+FROM sheet s+WHERE tr.sheet_id = s.id;++-- Backfill task.payload JSONB (Task proto)+-- Converts sheetId (int) to sheetSha256 (hex string)+UPDATE task t+SET payload = jsonb_set(+ payload - 'sheetId',+ '{sheetSha256}',+ to_jsonb(encode(s.sha256, 'hex'))+)+FROM sheet s+WHERE (t.payload->>'sheetId')::int = s.id+AND t.payload ? 'sheetId';++-- Drop old column+ALTER TABLE task_run DROP COLUMN sheet_id;++-- Drop sheet table entirely+DROP TABLE sheet;+```++**Step 3: Update LATEST.sql**++Edit `backend/migrator/migration/LATEST.sql`:++Find the `sheet` table definition (around line 177) and remove it entirely:+```sql+-- DELETE THESE LINES:+-- sheet table stores general statements.+CREATE TABLE sheet (+ id serial PRIMARY KEY,+ creator text NOT NULL REFERENCES principal(email) ON UPDATE CASCADE,+ created_at timestamptz NOT NULL DEFAULT now(),+ project text NOT NULL REFERENCES project(resource_id),+ name text NOT NULL,+ sha256 bytea NOT NULL,+ -- Stored as SheetPayload (proto/store/store/sheet.proto)+ payload jsonb NOT NULL DEFAULT '{}'+);++CREATE INDEX idx_sheet_project ON sheet(project);++ALTER SEQUENCE sheet_id_seq RESTART WITH 101;+```++Find `task_run` table definition (around line 227) and update:+```sql+-- Before:+sheet_id integer REFERENCES sheet(id),++-- After:+sheet_sha256 bytea REFERENCES sheet_blob(sha256),+```++**Step 4: Format SQL**++Run: `buf format -w proto` (SQL formatting if available)+Expected: Files formatted or no-op++**Step 5: Commit migration**++```bash+git add backend/migrator/migration/4.0/ backend/migrator/migration/LATEST.sql+git commit -m "feat: add migration for content-addressed sheets++- Add task_run.sheet_sha256 column+- Backfill from existing sheet table+- Backfill task.payload JSONB+- Drop sheet table++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 7: Update Migrator Test++**Files:**+- Modify: `backend/migrator/migrator_test.go`++**Step 1: Find TestLatestVersion**++Run: `grep -n "TestLatestVersion" backend/migrator/migrator_test.go`+Expected: Line number of test++**Step 2: Update test to expect version 4.0**++Edit `backend/migrator/migrator_test.go`, find the test and update the expected latest version:++```go+// Find the assertion that checks latest version+// Update from "3.9" to "4.0"+```++**Step 3: Run the migrator test**++Run: `go test -v -count=1 github.com/bytebase/bytebase/backend/migrator -run ^TestLatestVersion$`+Expected: PASS++**Step 4: Commit test update**++```bash+git add backend/migrator/migrator_test.go+git commit -m "test: update migrator test for version 4.0++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 8: Update Sheet API Service++**Files:**+- Modify: `backend/api/v1/sheet_service.go`++**Step 1: Find GetSheet method**++Run: `grep -n "func.*GetSheet" backend/api/v1/sheet_service.go`+Expected: Line numbers of GetSheet methods++**Step 2: Update GetSheet to parse SHA256 from resource name**++Update the method to:+1. Parse `projects/{project}/sheets/{sha256}` resource name+2. Extract sha256 hex string (not integer ID)+3. Call `store.GetSheetFull(ctx, sha256Hex)` instead of `store.GetSheetFull(ctx, id)`+4. Build response with resource name including sha256++**Step 3: Find CreateSheet method**++Run: `grep -n "func.*CreateSheet" backend/api/v1/sheet_service.go`+Expected: Line number++**Step 4: Update CreateSheet response**++Update to return resource name with SHA256:+```go+sheetName := fmt.Sprintf("projects/%s/sheets/%s", projectID, sheet.Sha256)+```++**Step 5: Update any other sheet service methods**++Search for all methods that reference sheet IDs and update them to use SHA256.++**Step 6: Run Go format**++Run: `gofmt -w backend/api/v1/sheet_service.go`+Expected: File formatted++**Step 7: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/sheet_service.go`+Expected: No errors (or fix any errors found)++**Step 8: Commit API service changes**++```bash+git add backend/api/v1/sheet_service.go+git commit -m "refactor: update sheet API to use SHA256 identifiers++Parse SHA256 from resource names instead of integer IDs.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 9: Update Plan Service++**Files:**+- Modify: `backend/api/v1/plan_service.go`+- Modify: `backend/api/v1/plan_service_converter.go`++**Step 1: Find sheet references in plan_service.go**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|sheet.UID\|sheet.GetSha256Hex" backend/api/v1/plan_service.go`+Expected: Line numbers where sheets are accessed++**Step 2: Update sheet access**++For each occurrence:+- Change from accessing `sheet.UID` to `sheet.Sha256`+- Change from `GetSheetMetadata(ctx, sheetID)` to `GetSheetMetadata(ctx, sha256Hex)`+- Remove calls to `sheet.GetSha256Hex()`, use `sheet.Sha256` directly++**Step 3: Find sheet references in plan_service_converter.go**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|SheetId\|sheet_id" backend/api/v1/plan_service_converter.go`+Expected: Line numbers++**Step 4: Update converters**++Update code that:+- Converts proto `sheet_id` (int32) to `sheet_sha256` (string)+- Builds resource names with SHA256 instead of integer IDs++**Step 5: Run Go format**++Run: `gofmt -w backend/api/v1/plan_service.go backend/api/v1/plan_service_converter.go`+Expected: Files formatted++**Step 6: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/plan_service*.go`+Expected: No errors (fix any that appear)++**Step 7: Commit changes**++```bash+git add backend/api/v1/plan_service.go backend/api/v1/plan_service_converter.go+git commit -m "refactor: update plan service to use sheet SHA256++Update converters and sheet access to use SHA256 identifiers.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 10: Update Rollout Service++**Files:**+- Modify: `backend/api/v1/rollout_service.go`+- Modify: `backend/api/v1/rollout_service_task.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|sheet.UID\|SheetId" backend/api/v1/rollout_service.go backend/api/v1/rollout_service_task.go`+Expected: Line numbers++**Step 2: Update all sheet access patterns**++For both files:+- Change `sheet.UID` to `sheet.Sha256`+- Change `task.SheetId` (int32) to `task.SheetSha256` (string)+- Update `GetSheetMetadata(ctx, id)` to `GetSheetMetadata(ctx, sha256Hex)`++**Step 3: Run Go format**++Run: `gofmt -w backend/api/v1/rollout_service*.go`+Expected: Files formatted++**Step 4: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/rollout_service*.go`+Expected: No errors++**Step 5: Commit changes**++```bash+git add backend/api/v1/rollout_service*.go+git commit -m "refactor: update rollout service to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 11: Update Release Service++**Files:**+- Modify: `backend/api/v1/release_service.go`+- Modify: `backend/api/v1/release_service_check.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|CreateSheets" backend/api/v1/release_service*.go`+Expected: Line numbers++**Step 2: Update CreateSheets calls**++Update calls to `CreateSheets`:+- Remove `projectID` parameter (no longer needed)+- Access `sheet.Sha256` instead of `sheet.UID`++**Step 3: Update sheet get calls**++Change from ID-based to SHA256-based lookups.++**Step 4: Run Go format**++Run: `gofmt -w backend/api/v1/release_service*.go`+Expected: Files formatted++**Step 5: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/release_service*.go`+Expected: No errors++**Step 6: Commit changes**++```bash+git add backend/api/v1/release_service*.go+git commit -m "refactor: update release service to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 12: Update TaskRun Executors++**Files:**+- Modify: `backend/runner/taskrun/executor.go`+- Modify: `backend/runner/taskrun/database_create_executor.go`+- Modify: `backend/runner/taskrun/database_migrate_executor.go`+- Modify: `backend/runner/taskrun/schema_update_sdl_executor.go`+- Modify: `backend/runner/taskrun/data_export_executor.go`++**Step 1: Find all sheet references in executor files**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|SheetId" backend/runner/taskrun/*.go`+Expected: Line numbers across multiple files++**Step 2: Update executor.go**++Edit `backend/runner/taskrun/executor.go`:+- Change `task.SheetId` to `task.SheetSha256`+- Update any sheet retrieval calls++**Step 3: Update database_create_executor.go**++Same pattern: `SheetId` → `SheetSha256`, ID lookups → SHA256 lookups++**Step 4: Update database_migrate_executor.go**++Same pattern.++**Step 5: Update schema_update_sdl_executor.go**++Same pattern.++**Step 6: Update data_export_executor.go**++Same pattern.++**Step 7: Run Go format**++Run: `gofmt -w backend/runner/taskrun/*.go`+Expected: Files formatted++**Step 8: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/runner/taskrun/`+Expected: No errors++**Step 9: Commit changes**++```bash+git add backend/runner/taskrun/+git commit -m "refactor: update taskrun executors to use sheet SHA256++All executors now use SHA256 identifiers for sheets.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 13: Update PlanCheck Executors++**Files:**+- Modify: `backend/runner/plancheck/statement_advise_executor.go`+- Modify: `backend/runner/plancheck/statement_report_executor.go`+- Modify: `backend/runner/plancheck/ghost_sync_executor.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|SheetId" backend/runner/plancheck/*.go`+Expected: Line numbers++**Step 2: Update all three executor files**++For each file, update:+- `task.SheetId` → `task.SheetSha256`+- Sheet retrieval to use SHA256++**Step 3: Run Go format**++Run: `gofmt -w backend/runner/plancheck/*.go`+Expected: Files formatted++**Step 4: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/runner/plancheck/`+Expected: No errors++**Step 5: Commit changes**++```bash+git add backend/runner/plancheck/+git commit -m "refactor: update plancheck executors to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 14: Update Approval Runner++**Files:**+- Modify: `backend/runner/approval/runner.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull" backend/runner/approval/runner.go`+Expected: Line numbers (if any)++**Step 2: Update sheet access (if present)**++Update any sheet-related code to use SHA256.++**Step 3: Run Go format**++Run: `gofmt -w backend/runner/approval/runner.go`+Expected: File formatted++**Step 4: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/runner/approval/`+Expected: No errors++**Step 5: Commit changes**++```bash+git add backend/runner/approval/runner.go+git commit -m "refactor: update approval runner to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 15: Update Revision Service++**Files:**+- Modify: `backend/api/v1/revision_service.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|CreateSheets" backend/api/v1/revision_service.go`+Expected: Line numbers++**Step 2: Update sheet operations**++Update to use SHA256-based access.++**Step 3: Run Go format**++Run: `gofmt -w backend/api/v1/revision_service.go`+Expected: File formatted++**Step 4: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/revision_service.go`+Expected: No errors++**Step 5: Commit changes**++```bash+git add backend/api/v1/revision_service.go+git commit -m "refactor: update revision service to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 16: Update Plan Service Plan Check++**Files:**+- Modify: `backend/api/v1/plan_service_plan_check.go`++**Step 1: Find sheet references**++Run: `grep -n "GetSheetMetadata\|GetSheetFull\|SheetId" backend/api/v1/plan_service_plan_check.go`+Expected: Line numbers++**Step 2: Update sheet access**++Update to use `task.SheetSha256` and SHA256-based lookups.++**Step 3: Run Go format**++Run: `gofmt -w backend/api/v1/plan_service_plan_check.go`+Expected: File formatted++**Step 4: Run golangci-lint**++Run: `golangci-lint run --allow-parallel-runners backend/api/v1/plan_service_plan_check.go`+Expected: No errors++**Step 5: Commit changes**++```bash+git add backend/api/v1/plan_service_plan_check.go+git commit -m "refactor: update plan check service to use sheet SHA256++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 17: Build and Run Linter++**Step 1: Build the entire backend**++Run: `go build -ldflags "-w -s" -p=16 -o ./bytebase-build/bytebase ./backend/bin/server/main.go`+Expected: Build succeeds++**Step 2: Run golangci-lint on entire codebase**++Run: `golangci-lint run --allow-parallel-runners`+Expected: No errors++**Step 3: If errors found, fix them iteratively**++Run: `golangci-lint run --fix --allow-parallel-runners`+Expected: Auto-fixes applied++Repeat step 2 until no errors remain.++**Step 4: Commit any lint fixes**++```bash+git add -A+git commit -m "fix: resolve linting issues for sheet SHA256 migration++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 18: Run Backend Tests++**Step 1: Run store tests**++Run: `go test -v -count=1 github.com/bytebase/bytebase/backend/store -run Sheet`+Expected: Tests pass (or identify failures to fix)++**Step 2: Run migrator tests**++Run: `go test -v -count=1 github.com/bytebase/bytebase/backend/migrator`+Expected: Tests pass++**Step 3: Run API tests**++Run: `go test -v -count=1 github.com/bytebase/bytebase/backend/api/v1 -run Sheet`+Expected: Tests pass++**Step 4: Fix any test failures**++If tests fail:+1. Analyze failure+2. Update test or code+3. Commit fix+4. Re-run tests++**Step 5: Commit test fixes (if any)**++```bash+git add -A+git commit -m "test: fix sheet tests for SHA256 migration++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 19: Update Frontend (if applicable)++**Note:** This task depends on frontend code structure. If frontend directly references sheet IDs, update to use SHA256.++**Step 1: Search for sheet ID references in frontend**++Run: `grep -r "sheets/" frontend/src --include="*.ts" --include="*.vue" | grep -v node_modules`+Expected: List of files with sheet references++**Step 2: Update TypeScript/Vue files**++For each file:+- Update resource name parsing to expect SHA256 instead of integers+- Update API calls to use SHA256++**Step 3: Run frontend type check**++Run: `pnpm --dir frontend type-check`+Expected: No type errors++**Step 4: Run frontend lint**++Run: `pnpm --dir frontend lint`+Expected: No lint errors++**Step 5: Run frontend format**++Run: `pnpm --dir frontend biome:check`+Expected: Files formatted++**Step 6: Commit frontend changes**++```bash+git add frontend/+git commit -m "refactor: update frontend to use sheet SHA256++Parse SHA256 from resource names instead of integer IDs.++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Task 20: Final Verification++**Step 1: Build entire project**++Run: `go build -ldflags "-w -s" -p=16 -o ./bytebase-build/bytebase ./backend/bin/server/main.go`+Expected: Build succeeds++**Step 2: Run full linter**++Run: `golangci-lint run --allow-parallel-runners`+Expected: No errors++**Step 3: Run all backend tests**++Run: `go test -v -count=1 ./backend/...`+Expected: All tests pass++**Step 4: Run frontend tests**++Run: `pnpm --dir frontend test`+Expected: All tests pass++**Step 5: Manual smoke test (optional)**++Start the server:+```bash+PG_URL=postgresql://bbdev@localhost/bbdev go run ./backend/bin/server/main.go --port 8080 --data . --debug+```++Test:+1. Create a sheet via API+2. Verify resource name uses SHA256+3. Retrieve sheet by SHA256+4. Create task with sheet reference+5. Verify task stores SHA256 correctly++**Step 6: Final commit (if any fixes needed)**++```bash+git add -A+git commit -m "fix: final adjustments for sheet SHA256 migration++🤖 Generated with [Claude Code](https://claude.com/claude-code)++Co-Authored-By: Claude Sonnet 4.5 <[email protected]>"+```++---++## Summary++This plan migrates sheets from ID-based to SHA256-based content addressing in 20 tasks:++1-5: Proto and struct changes+6-7: Database migration+8-16: Update all callers (API services, runners, executors)+17-18: Build and test backend+19: Update frontend+20: Final verification++Each task is atomic and can be committed independently. Follow TDD principles where applicable. Run linters after each task to catch issues early.diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 3441769d39..dc950609fa 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -762,7 +762,7 @@ Metadata about the request.| ----- | ---- | ----- | ----------- || task_run | [string](#string) | | Format: projects/{project}/rollouts/{rollout}/stages/{stage}/tasks/{task}/taskruns/{taskrun} || revision | [int64](#int64) | | The revision uid. optional |-| sheet | [string](#string) | | The sheet that holds the content. Format: projects/{project}/sheets/{sheet} |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || version | [string](#string) | | || type | [ChangelogPayload.Type](#bytebase-store-ChangelogPayload-Type) | | || git_commit | [string](#string) | | |@@ -2700,8 +2700,8 @@ Plan spec update event (tracks sheet changes to plan specs)| Field | Type | Label | Description || ----- | ---- | ----- | ----------- || spec | [string](#string) | | The spec that was updated Format: projects/{project}/plans/{plan}/specs/{spec} |-| from_sheet | [string](#string) | optional | Format: projects/{project}/sheets/{sheet} |-| to_sheet | [string](#string) | optional | Format: projects/{project}/sheets/{sheet} |+| from_sheet_sha256 | [string](#string) | optional | The SHA256 hash of the previous sheet content (hex-encoded). |+| to_sheet_sha256 | [string](#string) | optional | The SHA256 hash of the new sheet content (hex-encoded). |@@ -2800,7 +2800,7 @@ Plan spec update event (tracks sheet changes to plan specs)| Field | Type | Label | Description || ----- | ---- | ----- | ----------- || targets | [string](#string) | repeated | The list of targets. Multi-database format: [instances/{instance-id}/databases/{database-name}]. Single database group format: [projects/{project}/databaseGroups/{databaseGroup}]. |-| sheet | [string](#string) | | The resource name of the sheet. Format: projects/{project}/sheets/{sheet} |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || release | [string](#string) | | The resource name of the release. Format: projects/{project}/releases/{release} || type | [PlanConfig.ChangeDatabaseConfig.Type](#bytebase-store-PlanConfig-ChangeDatabaseConfig-Type) | | || ghost_flags | [PlanConfig.ChangeDatabaseConfig.GhostFlagsEntry](#bytebase-store-PlanConfig-ChangeDatabaseConfig-GhostFlagsEntry) | repeated | |@@ -2891,7 +2891,7 @@ Plan spec update event (tracks sheet changes to plan specs)| Field | Type | Label | Description || ----- | ---- | ----- | ----------- || targets | [string](#string) | repeated | The list of targets. Multi-database format: [instances/{instance-id}/databases/{database-name}]. Single database group format: [projects/{project}/databaseGroups/{databaseGroup}]. |-| sheet | [string](#string) | | The resource name of the sheet. Format: projects/{project}/sheets/{sheet} |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || format | [ExportFormat](#bytebase-store-ExportFormat) | | The format of the exported file. || password | [string](#string) | optional | The zip password provided by users. Leave it empty if there is no need to encrypt the zip file. |@@ -3018,7 +3018,7 @@ Type is the database change type.| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| sheet_uid | [int32](#int32) | | |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || instance_id | [string](#string) | | || database_name | [string](#string) | | || ghost_flags | [PlanCheckRunConfig.GhostFlagsEntry](#bytebase-store-PlanCheckRunConfig-GhostFlagsEntry) | repeated | |@@ -3638,8 +3638,7 @@ NOTIFY_ISSUE_APPROVED represents the issue approved notification. || ----- | ---- | ----- | ----------- || id | [string](#string) | | The unique identifier for the file. || path | [string](#string) | | The path of the file, e.g., `2.2/V0001_create_table.sql`. |-| sheet | [string](#string) | | The sheet that holds the content. Format: projects/{project}/sheets/{sheet} |-| sheet_sha256 | [string](#string) | | The SHA256 hash value of the sheet. |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || type | [SchemaChangeType](#bytebase-store-SchemaChangeType) | | || version | [string](#string) | | || enable_ghost | [bool](#bool) | | Whether to use gh-ost for online schema migration. |@@ -3970,8 +3969,7 @@ The severity level for SQL review rules.| ----- | ---- | ----- | ----------- || release | [string](#string) | | Format: projects/{project}/releases/{release} Can be empty. || file | [string](#string) | | Format: projects/{project}/releases/{release}/files/{id} Can be empty. |-| sheet | [string](#string) | | The sheet that holds the content. Format: projects/{project}/sheets/{sheet} |-| sheet_sha256 | [string](#string) | | The SHA256 hash value of the sheet. |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || task_run | [string](#string) | | The task run associated with the revision. Can be empty. Format: projects/{project}/rollouts/{rollout}/stages/{stage}/tasks/{task}/taskRuns/{taskRun} || type | [SchemaChangeType](#bytebase-store-SchemaChangeType) | | The type of the revision. |@@ -4681,7 +4679,7 @@ Task is the metadata for database operation tasks.| skipped | [bool](#bool) | | Whether the task was skipped during execution. || skipped_reason | [string](#string) | | Reason why the task was skipped. || spec_id | [string](#string) | | UUID that identifies the spec this task implements. |-| sheet_id | [int32](#int32) | | The sheet ID containing SQL statements for this task. |+| sheet_sha256 | [string](#string) | | The SHA256 hash of the sheet content (hex-encoded). || environment_id | [string](#string) | | The environment where the database will be created. || database_name | [string](#string) | | Name of the database to create. || table_name | [string](#string) | | Optional table name to create (required for some databases like MongoDB). |diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex f0a67965c7..70c5bf953e 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -2519,11 +2519,10 @@ optional </p></td></tr><tr>- <td>sheet</td>+ <td>sheet_sha256</td><td><a href="#string">string</a></td><td></td>- <td><p>The sheet that holds the content.-Format: projects/{project}/sheets/{sheet} </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -8018,17 +8017,17 @@ Format: projects/{project}/plans/{plan}/specs/{spec} </p></td></tr><tr>- <td>from_sheet</td>+ <td>from_sheet_sha256</td><td><a href="#string">string</a></td><td>optional</td>- <td><p>Format: projects/{project}/sheets/{sheet} </p></td>+ <td><p>The SHA256 hash of the previous sheet content (hex-encoded). </p></td></tr><tr>- <td>to_sheet</td>+ <td>to_sheet_sha256</td><td><a href="#string">string</a></td><td>optional</td>- <td><p>Format: projects/{project}/sheets/{sheet} </p></td>+ <td><p>The SHA256 hash of the new sheet content (hex-encoded). </p></td></tr></tbody>@@ -8200,11 +8199,10 @@ Single database group format: [projects/{project}/databaseGroups/{databaseGroup}</tr><tr>- <td>sheet</td>+ <td>sheet_sha256</td><td><a href="#string">string</a></td><td></td>- <td><p>The resource name of the sheet.-Format: projects/{project}/sheets/{sheet} </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -8439,11 +8437,10 @@ Single database group format: [projects/{project}/databaseGroups/{databaseGroup}</tr><tr>- <td>sheet</td>+ <td>sheet_sha256</td><td><a href="#string">string</a></td><td></td>- <td><p>The resource name of the sheet.-Format: projects/{project}/sheets/{sheet} </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -8684,10 +8681,10 @@ Leave it empty if there is no need to encrypt the zip file. </p></td><tbody><tr>- <td>sheet_uid</td>- <td><a href="#int32">int32</a></td>+ <td>sheet_sha256</td>+ <td><a href="#string">string</a></td><td></td>- <td><p> </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -10025,19 +10022,11 @@ NOTIFY_ISSUE_APPROVED represents the issue approved notification.</p></td><td><p>The path of the file, e.g., `2.2/V0001_create_table.sql`. </p></td></tr>- <tr>- <td>sheet</td>- <td><a href="#string">string</a></td>- <td></td>- <td><p>The sheet that holds the content.-Format: projects/{project}/sheets/{sheet} </p></td>- </tr>-<tr><td>sheet_sha256</td><td><a href="#string">string</a></td><td></td>- <td><p>The SHA256 hash value of the sheet. </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -11115,19 +11104,11 @@ Can be empty. </p></td>Can be empty. </p></td></tr>- <tr>- <td>sheet</td>- <td><a href="#string">string</a></td>- <td></td>- <td><p>The sheet that holds the content.-Format: projects/{project}/sheets/{sheet} </p></td>- </tr>-<tr><td>sheet_sha256</td><td><a href="#string">string</a></td><td></td>- <td><p>The SHA256 hash value of the sheet. </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>@@ -12759,10 +12740,10 @@ Default to this mode.</p></td></tr><tr>- <td>sheet_id</td>- <td><a href="#int32">int32</a></td>+ <td>sheet_sha256</td>+ <td><a href="#string">string</a></td><td></td>- <td><p>The sheet ID containing SQL statements for this task. </p></td>+ <td><p>The SHA256 hash of the sheet content (hex-encoded). </p></td></tr><tr>diff --git a/proto/store/store/changelog.proto b/proto/store/store/changelog.protoindex a082ad9a51..dae63a0806 100644--- a/proto/store/store/changelog.proto+++ b/proto/store/store/changelog.proto@@ -12,9 +12,8 @@ message ChangelogPayload {// optionalint64 revision = 2;- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- string sheet = 3;+ // The SHA256 hash of the sheet content (hex-encoded).+ string sheet_sha256 = 3;string version = 4;diff --git a/proto/store/store/issue_comment.proto b/proto/store/store/issue_comment.protoindex bf67731f63..4b5088a1e7 100644--- a/proto/store/store/issue_comment.proto+++ b/proto/store/store/issue_comment.proto@@ -36,9 +36,9 @@ message IssueCommentPayload {// The spec that was updated// Format: projects/{project}/plans/{plan}/specs/{spec}string spec = 1;- // Format: projects/{project}/sheets/{sheet}- optional string from_sheet = 2;- // Format: projects/{project}/sheets/{sheet}- optional string to_sheet = 3;+ // The SHA256 hash of the previous sheet content (hex-encoded).+ optional string from_sheet_sha256 = 2;+ // The SHA256 hash of the new sheet content (hex-encoded).+ optional string to_sheet_sha256 = 3;}}diff --git a/proto/store/store/plan.proto b/proto/store/store/plan.protoindex 0b00eeba93..58c8047b25 100644--- a/proto/store/store/plan.proto+++ b/proto/store/store/plan.proto@@ -49,9 +49,8 @@ message PlanConfig {// Multi-database format: [instances/{instance-id}/databases/{database-name}].// Single database group format: [projects/{project}/databaseGroups/{databaseGroup}].repeated string targets = 10;- // The resource name of the sheet.- // Format: projects/{project}/sheets/{sheet}- string sheet = 2;+ // The SHA256 hash of the sheet content (hex-encoded).+ string sheet_sha256 = 2;// The resource name of the release.// Format: projects/{project}/releases/{release}string release = 9;@@ -80,9 +79,8 @@ message PlanConfig {// Multi-database format: [instances/{instance-id}/databases/{database-name}].// Single database group format: [projects/{project}/databaseGroups/{databaseGroup}].repeated string targets = 5;- // The resource name of the sheet.- // Format: projects/{project}/sheets/{sheet}- string sheet = 2;+ // The SHA256 hash of the sheet content (hex-encoded).+ string sheet_sha256 = 2;// The format of the exported file.ExportFormat format = 3;// The zip password provided by users.diff --git a/proto/store/store/plan_check_run.proto b/proto/store/store/plan_check_run.protoindex 11504a21af..50c6274387 100644--- a/proto/store/store/plan_check_run.proto+++ b/proto/store/store/plan_check_run.proto@@ -8,7 +8,8 @@ import "store/common.proto";option go_package = "generated-go/store";message PlanCheckRunConfig {- int32 sheet_uid = 1;+ // The SHA256 hash of the sheet content (hex-encoded).+ string sheet_sha256 = 1;string instance_id = 2;string database_name = 3;diff --git a/proto/store/store/release.proto b/proto/store/store/release.protoindex 4df5ff024a..4c3510b1ba 100644--- a/proto/store/store/release.proto+++ b/proto/store/store/release.proto@@ -2,7 +2,6 @@ syntax = "proto3";package bytebase.store;-import "google/api/resource.proto";import "store/common.proto";option go_package = "generated-go/store";@@ -19,10 +18,8 @@ message ReleasePayload {string id = 1;// The path of the file, e.g., `2.2/V0001_create_table.sql`.string path = 2;- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- string sheet = 3 [(google.api.resource_reference) = {type: "bytebase.com/Sheet"}];- // The SHA256 hash value of the sheet.+ reserved 3; // Previously: string sheet (resource name)+ // The SHA256 hash of the sheet content (hex-encoded).string sheet_sha256 = 4;SchemaChangeType type = 5;string version = 6;diff --git a/proto/store/store/revision.proto b/proto/store/store/revision.protoindex 8a732c452d..3bc8480916 100644--- a/proto/store/store/revision.proto+++ b/proto/store/store/revision.proto@@ -16,10 +16,8 @@ message RevisionPayload {// Can be empty.string file = 2;- // The sheet that holds the content.- // Format: projects/{project}/sheets/{sheet}- string sheet = 3 [(google.api.resource_reference) = {type: "bytebase.com/Sheet"}];- // The SHA256 hash value of the sheet.+ reserved 3; // Previously: string sheet (resource name)+ // The SHA256 hash of the sheet content (hex-encoded).string sheet_sha256 = 4;// The task run associated with the revision.diff --git a/proto/store/store/task.proto b/proto/store/store/task.protoindex f9ade8c5b7..ac22c1fa9c 100644--- a/proto/store/store/task.proto+++ b/proto/store/store/task.proto@@ -27,8 +27,8 @@ message Task {string skipped_reason = 2;// UUID that identifies the spec this task implements.string spec_id = 3;- // The sheet ID containing SQL statements for this task.- int32 sheet_id = 4;+ // The SHA256 hash of the sheet content (hex-encoded).+ string sheet_sha256 = 4;// The environment where the database will be created.string environment_id = 5;