MCPcopy Create free account
hub / github.com/bytebase/bytebase / GenerateRestoreSQL

Function GenerateRestoreSQL

backend/plugin/parser/mysql/restore.go:26–46  ·  view source on GitHub ↗
(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item)

Source from the content-addressed store, hash-verified

24}
25
26func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error) {
27 originalSQL, err := extractStatement(statement, backupItem)
28 if err != nil {
29 return "", errors.Errorf("failed to extract single SQL: %v", err)
30 }
31
32 // Parse the filtered SQL and find the first DML node.
33 matchingNode, err := findFirstDML(originalSQL)
34 if err != nil {
35 return "", err
36 }
37 if matchingNode == nil {
38 return "", errors.Errorf("no DML statement found in extracted SQL")
39 }
40
41 sqlForComment, truncated := common.TruncateString(originalSQL, maxCommentLength)
42 if truncated {
43 sqlForComment += "..."
44 }
45 return doGenerate(ctx, rCtx, sqlForComment, matchingNode, backupItem)
46}
47
48func findFirstDML(statement string) (ast.Node, error) {
49 stmtList, err := ParseMySQLOmni(statement)

Callers 1

TestRestoreFunction · 0.70

Calls 5

TruncateStringFunction · 0.92
findFirstDMLFunction · 0.85
ErrorfMethod · 0.80
extractStatementFunction · 0.70
doGenerateFunction · 0.70

Tested by 1

TestRestoreFunction · 0.56