Skip to content

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

refactor: rename GetSheetMetadata to GetSheetTruncated (#18556)

Danny Xu6a041a9357cd
diff --git a/backend/api/v1/release_service.go b/backend/api/v1/release_service.go
index c2c84a6f82..2f02ba7b7e 100644
--- a/backend/api/v1/release_service.go
+++ b/backend/api/v1/release_service.go
@@ -437,7 +437,7 @@ func convertToRelease(ctx context.Context, s *store.Store, release *store.Releas
}
for _, f := range release.Payload.Files {
- sheet, err := s.GetSheetMetadata(ctx, f.SheetSha256)
+ sheet, err := s.GetSheetTruncated(ctx, f.SheetSha256)
if err != nil {
return nil, errors.Wrapf(err, "failed to get sheet %q", f.SheetSha256)
}
diff --git a/backend/api/v1/revision_service.go b/backend/api/v1/revision_service.go
index aac7a5e4ea..7e70c86769 100644
--- a/backend/api/v1/revision_service.go
+++ b/backend/api/v1/revision_service.go
@@ -278,7 +278,7 @@ 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) {
sheetSha256 := revision.Payload.SheetSha256
- sheet, err := s.GetSheetMetadata(ctx, sheetSha256)
+ sheet, err := s.GetSheetTruncated(ctx, sheetSha256)
if err != nil {
return nil, errors.Wrapf(err, "failed to get sheet %q", sheetSha256)
}
diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.go
index f57eb9cb25..f2f2f893f9 100644
--- a/backend/api/v1/sheet_service.go
+++ b/backend/api/v1/sheet_service.go
@@ -149,7 +149,7 @@ func (s *SheetService) GetSheet(ctx context.Context, request *connect.Request[v1
if request.Msg.Raw {
sheet, sheetErr = s.store.GetSheetFull(ctx, sheetSha256)
} else {
- sheet, sheetErr = s.store.GetSheetMetadata(ctx, sheetSha256)
+ sheet, sheetErr = s.store.GetSheetTruncated(ctx, sheetSha256)
}
if sheetErr != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(sheetErr, "failed to get sheet"))
diff --git a/backend/runner/plancheck/statement_advise_executor.go b/backend/runner/plancheck/statement_advise_executor.go
index b8eef9aa86..05ffa20e46 100644
--- a/backend/runner/plancheck/statement_advise_executor.go
+++ b/backend/runner/plancheck/statement_advise_executor.go
@@ -45,14 +45,14 @@ 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) {
- sheet, err := e.store.GetSheetMetadata(ctx, config.SheetSha256)
+ fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)
if err != nil {
- return nil, errors.Wrapf(err, "failed to get sheet %s", config.SheetSha256)
+ return nil, err
}
- if sheet == nil {
- return nil, errors.Errorf("sheet %s not found", config.SheetSha256)
+ if fullSheet == nil {
+ return nil, errors.Errorf("sheet full %s not found", config.SheetSha256)
}
- if sheet.Size > common.MaxSheetCheckSize {
+ if fullSheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
Status: storepb.Advice_WARNING,
@@ -62,14 +62,6 @@ func (e *StatementAdviseExecutor) Run(ctx context.Context, config *storepb.PlanC
},
}, nil
}
- fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)
- if err != nil {
- return nil, err
- }
- if fullSheet == nil {
- return nil, errors.Errorf("sheet full %s not found", config.SheetSha256)
- }
- statement := fullSheet.Statement
enablePriorBackup := config.EnablePriorBackup
enableGhost := config.EnableGhost
enableSDL := config.EnableSdl
@@ -100,7 +92,7 @@ func (e *StatementAdviseExecutor) Run(ctx context.Context, config *storepb.PlanC
return nil, errors.Errorf("database not found %q", config.DatabaseName)
}
- results, err := e.runReview(ctx, instance, database, statement, enablePriorBackup, enableGhost, enableSDL)
+ results, err := e.runReview(ctx, instance, database, fullSheet.Statement, enablePriorBackup, enableGhost, enableSDL)
if err != nil {
return nil, err
}
diff --git a/backend/runner/plancheck/statement_report_executor.go b/backend/runner/plancheck/statement_report_executor.go
index 12f5d778b8..91041c495c 100644
--- a/backend/runner/plancheck/statement_report_executor.go
+++ b/backend/runner/plancheck/statement_report_executor.go
@@ -48,14 +48,14 @@ type StatementReportExecutor struct {
// Run runs the statement report executor.
func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanCheckRunConfig) ([]*storepb.PlanCheckRunResult_Result, error) {
- sheet, err := e.store.GetSheetMetadata(ctx, config.SheetSha256)
+ fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)
if err != nil {
- return nil, errors.Wrapf(err, "failed to get sheet %s", config.SheetSha256)
+ return nil, err
}
- if sheet == nil {
- return nil, errors.Errorf("sheet %s not found", config.SheetSha256)
+ if fullSheet == nil {
+ return nil, errors.Errorf("sheet full %s not found", config.SheetSha256)
}
- if sheet.Size > common.MaxSheetCheckSize {
+ if fullSheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
Status: storepb.Advice_WARNING,
@@ -65,14 +65,6 @@ func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanC
},
}, nil
}
- fullSheet, err := e.store.GetSheetFull(ctx, config.SheetSha256)
- if err != nil {
- return nil, err
- }
- if fullSheet == nil {
- return nil, errors.Errorf("sheet full %s not found", config.SheetSha256)
- }
- statement := fullSheet.Statement
instance, err := e.store.GetInstance(ctx, &store.FindInstanceMessage{ResourceID: &config.InstanceId})
if err != nil {
@@ -101,7 +93,7 @@ func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanC
}
// Check statement syntax error.
- _, syntaxAdvices := e.sheetManager.GetStatementsForChecks(instance.Metadata.GetEngine(), statement)
+ _, syntaxAdvices := e.sheetManager.GetStatementsForChecks(instance.Metadata.GetEngine(), fullSheet.Statement)
if len(syntaxAdvices) > 0 {
advice := syntaxAdvices[0]
return []*storepb.PlanCheckRunResult_Result{
@@ -125,7 +117,7 @@ func (e *StatementReportExecutor) Run(ctx context.Context, config *storepb.PlanC
Code: common.Ok.Int32(),
Title: "OK",
}
- summaryReport, err := GetSQLSummaryReport(ctx, e.store, e.sheetManager, e.dbFactory, database, statement)
+ summaryReport, err := GetSQLSummaryReport(ctx, e.store, e.sheetManager, e.dbFactory, database, fullSheet.Statement)
if err != nil {
return nil, err
}
diff --git a/backend/store/sheet.go b/backend/store/sheet.go
index 5c3893612f..e18792693a 100644
--- a/backend/store/sheet.go
+++ b/backend/store/sheet.go
@@ -24,10 +24,10 @@ type SheetMessage struct {
Size int64
}
-// GetSheetMetadata gets a sheet by SHA256 hash with truncated statement (max 2MB).
+// GetSheetTruncated gets a sheet by SHA256 hash with truncated statement (max 2MB).
// Statement field will be truncated to MaxSheetSize (2MB).
// Results are cached by SHA256 hex string.
-func (s *Store) GetSheetMetadata(ctx context.Context, sha256Hex string) (*SheetMessage, error) {
+func (s *Store) GetSheetTruncated(ctx context.Context, sha256Hex string) (*SheetMessage, error) {
if v, ok := s.sheetMetadataCache.Get(sha256Hex); ok && s.enableCache {
return v, nil
}