Skip to content

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

feat: implement syntax check for sdl (#17184)

rebelice49ee8b88b1af
diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.go
index b038ba3d76..45a0042caa 100644
--- a/backend/api/v1/release_service_check.go
+++ b/backend/api/v1/release_service_check.go
@@ -183,7 +183,54 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, req *connect.Request[
}
}
}
- return nil, connect.NewError(connect.CodeUnimplemented, errors.New("declarative release files are not supported yet"))
+
+ // Perform syntax check for declarative files
+ for _, file := range request.Release.Files {
+ if stopChecking {
+ break
+ }
+
+ checkResult := &v1pb.CheckReleaseResponse_CheckResult{
+ File: file.Path,
+ Target: common.FormatDatabase(instance.ResourceID, database.DatabaseName),
+ }
+
+ // statement is guaranteed to be populated by validateAndSanitizeReleaseFiles
+ statement := string(file.Statement)
+
+ // Check if any syntax error in the statement.
+ if common.EngineSupportSyntaxCheck(engine) {
+ _, syntaxAdvices := s.sheetManager.GetASTsForChecks(engine, statement)
+ if len(syntaxAdvices) > 0 {
+ for _, advice := range syntaxAdvices {
+ checkResult.Advices = append(checkResult.Advices, convertToV1Advice(advice))
+ }
+ }
+ }
+
+ // Only add to results if there are syntax errors
+ if len(checkResult.Advices) > 0 {
+ response.Results = append(response.Results, checkResult)
+ for _, advice := range checkResult.Advices {
+ switch advice.Status {
+ case v1pb.Advice_ERROR:
+ if errorAdviceCount < common.MaximumAdvicePerStatus {
+ errorAdviceCount++
+ }
+ case v1pb.Advice_WARNING:
+ if warningAdviceCount < common.MaximumAdvicePerStatus {
+ warningAdviceCount++
+ }
+ default:
+ }
+ }
+ // Check if we need to stop checking for the rest of files.
+ // If we have reached the maximum number of advices for both error and warning, we will stop checking.
+ if errorAdviceCount >= common.MaximumAdvicePerStatus && warningAdviceCount >= common.MaximumAdvicePerStatus {
+ stopChecking = true
+ }
+ }
+ }
case v1pb.Release_File_VERSIONED:
// Batch fetch all revisions for this database
revisions, err := s.store.ListRevisions(ctx, &store.FindRevisionMessage{