Repository navigation
feat(rules): add SQL review rules - #1941
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
|
Verified locally on
No issues from my side. AI disclosure: verification drafted with DeepSeek Harness ( |
|
Thanks for the second look on macOS arm64, @Walternater, appreciated. |
|
Merged the latest main into this branch to clear the conflict in internal/config/rules/system_rules_test.go. Both the new SQL test cases and the Move cases from main are kept. go build, go vet, and go test ./internal/config/... pass on 7743d35. |
wu21-web
left a comment
There was a problem hiding this comment.
🟡 Queued to merge.
There are 3 pull requests ahead of this submission.
|
Thanks for merging this, @lizhengfeng101. Schema migrations and hand-written queries now get a dialect-aware SQL review prompt, with checks for destructive migrations and locking hazards. |
Description
.sqlis already on the review allowlist, butsystem_rules.jsonhad no SQL mapping, so schema migrations, stored procedures, and hand-written queries all receiveddefault.md. This change adds a built-in SQL rule document and maps**/*.sqlto it.internal/config/rules/rule_docs/sql.mdis a precision-first, dialect-aware review prompt (PostgreSQL, MySQL, SQLite, SQL Server). It defers formatting to linters such assqlfluffand covers destructive or irreversible migrations, locking and online-migration hazards, NULL semantics, join/filter correctness, constraints and integrity, non-sargable predicates andSELECT *, and dynamic SQL /SECURITY DEFINERprivilege issues.Only
**/*.sqlis mapped. The allowlist admits.sqland does not admit.psql,.pgsql, or.ddl; those extensions were not added. The MyBatis mapper XML rule (**/*{mapper,dao}*.xml→mapper_dao_xml.md) is unchanged and still wins for mapper XML.The
**/*.sqlentry is last inpath_rule_map. It does not overlap a more specific glob. Removing that single mapping makesResolvefall back todefault.mdfordb/migrate/20260101_add_users.sqlandsql/reports/monthly.sql,TestResolveDetail_SystemSQLPatternMatchreportsPattern: default,TestSystemRulesIntegrity/no_orphan_filesflagssql.md, and all five review-rules locales fail because they still list**/*.sql. Restoring the mapping makes those tests pass again.Type of Change
How Has This Been Tested?
make testpasses locallyManual testing (describe below)
go test ./internal/config/...— 5 packages ok (allowlist,rules,template,testconnection,toolsconfig)go test ./internal/config/rules -count=1 -run 'TestResolve_DefaultRules|TestResolveDetail_SystemSQLPatternMatch|TestSystemRulesIntegrity|TestReviewRulesGuideLists'— PASS, includingdb/migrate/20260101_add_users.sql,sql/reports/monthly.sql,SQL/REPORTS/MONTHLY.SQL,**/*.sqlallowlisted, and all five locale tablesFail-before (mapping removed in a worktree): the SQL ResolveDetail rows,
no_orphan_files, andTestReviewRulesGuideListsEverySystemRulePatternfail withPattern: default/ orphansql.md/ missing glob; restore then PASSmake build— PASS (dist/opencodereview)make test— PASS, 2736--- PASS:lines, 0--- FAIL:, 26 packages okmake check— PASS (license headers, english-check,go mod tidy,gofmt -s -w,go vet)gofmt -l .— emptygo vet ./internal/config/...— PASSManual:
/tmp/ocr-main(upstreamd77d70b)rules checkondb/migrate/20260101_add_index.sqlandsql/reports/monthly.sqlprintsPattern: default./tmp/ocr-sql(6cc1fa1) printsPattern: **/*.sqland the SQL rule.mapper/UserMapper.xmlstaysPattern: **/*{mapper,dao}*.xmlon both binaries.ocr review --preview(no model call) lists the three files as will-review and does not print the per-file rule body.Not verified: a live review that calls a model, CI on this branch, and files with extensions other than
.sql.Checklist
go fmt,go vet)AI disclosure: written with AI assistance (Cursor, grok-4.6); the need, scope and review are mine.
Related Issues
No existing issue covers SQL review rules.
Demo