Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: load preview of a sheet by default (#3953)
Danny Xuca21c8a133a0
diff --git a/api/sheet.go b/api/sheet.goindex cf09a53221..df4127d554 100644--- a/api/sheet.go+++ b/api/sheet.go@@ -78,6 +78,9 @@ type Sheet struct {Payload string `jsonapi:"attr,payload"`Starred bool `jsonapi:"attr,starred"`Pinned bool `jsonapi:"attr,pinned"`++ // Size is the size of statement in bytes.+ Size int64 `jsonapi:"attr,size"`}// SheetCreate is the API message for creating a sheet.@@ -125,6 +128,8 @@ type SheetFind struct {// Used to find the creator's sheet list.// When finding shared PROJECT/PUBLIC sheets, this value should be empty.CreatorID *int+ // LoadFull is used if we want to load the full sheet.+ LoadFull bool// Related fieldsProjectID *intdiff --git a/server/runner/taskrun/data_update_executor.go b/server/runner/taskrun/data_update_executor.goindex 9eddbbcdf3..16a6c0ac03 100644--- a/server/runner/taskrun/data_update_executor.go+++ b/server/runner/taskrun/data_update_executor.go@@ -44,7 +44,7 @@ func (exec *DataUpdateExecutor) RunOnce(ctx context.Context, task *api.Task) (testatement := payload.Statementif payload.SheetID > 0 {- sheet, err := exec.store.GetSheet(ctx, &api.SheetFind{ID: &payload.SheetID}, api.SystemBotID)+ sheet, err := exec.store.GetSheet(ctx, &api.SheetFind{ID: &payload.SheetID, LoadFull: true}, api.SystemBotID)if err != nil {return true, nil, err}diff --git a/server/runner/taskrun/schema_update_executor.go b/server/runner/taskrun/schema_update_executor.goindex ddc12f4547..0ce39248e5 100644--- a/server/runner/taskrun/schema_update_executor.go+++ b/server/runner/taskrun/schema_update_executor.go@@ -49,7 +49,7 @@ func (exec *SchemaUpdateExecutor) RunOnce(ctx context.Context, task *api.Task) (statement := payload.Statementif payload.SheetID > 0 {- sheet, err := exec.store.GetSheet(ctx, &api.SheetFind{ID: &payload.SheetID}, api.SystemBotID)+ sheet, err := exec.store.GetSheet(ctx, &api.SheetFind{ID: &payload.SheetID, LoadFull: true}, api.SystemBotID)if err != nil {return true, nil, err}diff --git a/store/sheet.go b/store/sheet.goindex 15e5c1eb94..27c17076c7 100644--- a/store/sheet.go+++ b/store/sheet.go@@ -39,6 +39,7 @@ type sheetRaw struct {Source api.SheetSourceType api.SheetTypePayload string+ Size int64}// toSheet creates an instance of Sheet based on the sheetRaw.@@ -68,6 +69,7 @@ func (raw *sheetRaw) toSheet() *api.Sheet {Source: raw.Source,Type: raw.Type,Payload: raw.Payload,+ Size: raw.Size,}}@@ -334,7 +336,7 @@ func createSheetImpl(ctx context.Context, tx *Tx, create *api.SheetCreate) (*shepayload)VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, project_id, database_id, name, statement, visibility, source, type, payload+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, project_id, database_id, name, LEFT(statement, 10240), visibility, source, type, payload, octet_length(statement)`var sheetRaw sheetRawdatabaseID := sql.NullInt32{}@@ -364,6 +366,7 @@ func createSheetImpl(ctx context.Context, tx *Tx, create *api.SheetCreate) (*she&sheetRaw.Source,&sheetRaw.Type,&sheetRaw.Payload,+ &sheetRaw.Size,); err != nil {if err == sql.ErrNoRows {return nil, common.FormatDBErrorEmptyRowWithQuery(query)@@ -407,7 +410,7 @@ func patchSheetImpl(ctx context.Context, tx *Tx, patch *api.SheetPatch) (*sheetRUPDATE sheetSET `+strings.Join(set, ", ")+`WHERE id = $%d- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, project_id, database_id, name, statement, visibility, source, type, payload+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, project_id, database_id, name, LEFT(statement, 10240), visibility, source, type, payload, octet_length(statement)`, len(args)),args...,).Scan(@@ -425,6 +428,7 @@ func patchSheetImpl(ctx context.Context, tx *Tx, patch *api.SheetPatch) (*sheetR&sheetRaw.Source,&sheetRaw.Type,&sheetRaw.Payload,+ &sheetRaw.Size,); err != nil {if err == sql.ErrNoRows {return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("sheet ID not found: %d", patch.ID)}@@ -478,8 +482,12 @@ func findSheetImpl(ctx context.Context, tx *Tx, find *api.SheetFind) ([]*sheetRaif v := find.Type; v != nil {where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)}+ statementField := "LEFT(statement, 10240)"+ if find.LoadFull {+ statementField = "statement"+ }- rows, err := tx.QueryContext(ctx, `+ rows, err := tx.QueryContext(ctx, fmt.Sprintf(`SELECTid,row_status,@@ -490,13 +498,14 @@ func findSheetImpl(ctx context.Context, tx *Tx, find *api.SheetFind) ([]*sheetRaproject_id,database_id,name,- statement,+ %s,visibility,source,type,- payload+ payload,+ octet_length(statement)FROM sheet- WHERE `+strings.Join(where, " AND "),+ WHERE %s`, statementField, strings.Join(where, " AND ")),args...,)if err != nil {@@ -523,6 +532,7 @@ func findSheetImpl(ctx context.Context, tx *Tx, find *api.SheetFind) ([]*sheetRa&sheetRaw.Source,&sheetRaw.Type,&sheetRaw.Payload,+ &sheetRaw.Size,); err != nil {return nil, FormatError(err)}