sql-review

GitHub

用于在合并前对 SQL 进行质量门禁检查。支持语法验证、26 种反模式扫描、注入安全检测及 PII 泄露审查,并基于可读性、性能等维度给出 A-F 评级,辅助代码审查与审计。

.opencode/skills/sql-review/SKILL.md AltimateAI/altimate-code

Trigger Scenarios

PR 合并前的 SQL 质量审查 获取 SQL 查询或模型的质量等级 批量审计目录下的 SQL 文件

Install

npx skills add AltimateAI/altimate-code --skill sql-review -g -y
More Options

Non-standard path

npx skills add https://github.com/AltimateAI/altimate-code/tree/main/.opencode/skills/sql-review -g -y

Use without installing

npx skills use AltimateAI/altimate-code@sql-review

指定 Agent (Claude Code)

npx skills add AltimateAI/altimate-code --skill sql-review -a claude-code -g -y

安装 repo 全部 skill

npx skills add AltimateAI/altimate-code --all -g -y

预览 repo 内 skill

npx skills add AltimateAI/altimate-code --list

SKILL.md

Frontmatter
{
    "name": "sql-review",
    "description": "Pre-merge SQL quality gate — lint 26 anti-patterns, grade readability\/performance A-F, validate syntax, and scan for injection threats. Use before committing or reviewing SQL changes."
}

SQL Review

Requirements

Agent: any (read-only analysis) Tools used: altimate_core_check, altimate_core_grade, sql_analyze, read, glob, bash (for git operations)

When to Use This Skill

Use when the user wants to:

  • Review SQL quality before merging a PR
  • Get a quality grade (A-F) on a query or model
  • Run a comprehensive lint + safety + syntax check in one pass
  • Audit SQL files in a directory for anti-patterns

Do NOT use for:

  • Optimizing query performance -> use query-optimize
  • Fixing broken SQL -> use dbt-troubleshoot
  • Translating between dialects -> use sql-translate

Workflow

1. Collect SQL to Review

Either:

  • Read SQL from a file path provided by the user
  • Accept SQL directly from the conversation
  • Auto-detect changed SQL files from git:
git diff --name-only HEAD~1 | grep '\.sql$'

For dbt models, compile first to get the full SQL:

altimate-dbt compile --model <name>

2. Run Comprehensive Check

Call altimate_core_check — this is the single-call code review that composes:

  • Syntax validation: Parse errors with line/column positions
  • Lint (26 anti-patterns): SELECT *, unused CTEs, implicit casts, NULL comparisons, missing WHERE on DELETE/UPDATE, cartesian joins, non-sargable predicates, missing partition filters, and more
  • Injection scan: Tautology attacks, UNION injection, stacked queries, comment injection, Jinja template injection
  • PII exposure: Flags queries accessing columns classified as PII
altimate_core_check(sql: <sql>, schema_context: <schema_object>)

3. Grade the SQL

Call altimate_core_grade to get an A-F quality score with per-category breakdown:

altimate_core_grade(sql: <sql>, schema_context: <schema_object>)

Categories scored:

  • Readability: Naming, formatting, CTE structure
  • Performance: Anti-patterns, index usage, scan efficiency
  • Correctness: NULL handling, join logic, type safety
  • Best Practices: Explicit columns, proper materialization hints

4. Run Anti-Pattern Analysis

Call sql_analyze for the detailed anti-pattern breakdown with severity levels and concrete recommendations:

sql_analyze(sql: <sql>, dialect: <dialect>)

5. Present the Review

SQL Review: <file_or_query_name>
==============================

Grade: B+ (82/100)
  Readability:  A  (clear CTEs, good naming)
  Performance:  B- (missing partition filter on large table)
  Correctness:  A  (proper NULL handling)
  Best Practices: C (SELECT * in staging model)

Issues Found: 3
  [HIGH]   SELECT_STAR — Use explicit column list for contract stability
  [MEDIUM] MISSING_PARTITION_FILTER — Add date filter to avoid full scan
  [LOW]    IMPLICIT_CAST — VARCHAR compared to INTEGER on line 23

Safety: PASS (no injection vectors detected)
PII: PASS (no PII columns exposed)

Verdict: Fix HIGH issues before merging. MEDIUM issues are recommended.

6. Batch Mode

When reviewing multiple files (e.g., all changed SQL in a PR):

  • Run the check on each file
  • Present a summary table:
| File | Grade | Issues | Safety | Verdict |
|------|-------|--------|--------|---------|
| stg_orders.sql | A | 0 | PASS | Ship |
| int_revenue.sql | B- | 2 | PASS | Fix HIGH |
| mart_daily.sql | C | 5 | WARN | Block |

Usage

  • /sql-review models/marts/fct_orders.sql -- Review a specific file
  • /sql-review -- Review all SQL files changed in the current git diff
  • /sql-review --all models/ -- Review all SQL files in a directory

Version History

  • 8c9a9a8 Current 2026-07-25 06:35

Same Skill Collection

.opencode/skills/altimate-setup/SKILL.md
.opencode/skills/cost-report/SKILL.md
.opencode/skills/data-parity/SKILL.md
.opencode/skills/dbt-analyze/SKILL.md
.opencode/skills/dbt-docs/SKILL.md
.opencode/skills/dbt-pr-review/SKILL.md
.opencode/skills/dbt-test/SKILL.md
.opencode/skills/dbt-troubleshoot/SKILL.md
.opencode/skills/dbt-unit-tests/SKILL.md
.opencode/skills/lineage-diff/SKILL.md
.opencode/skills/pii-audit/SKILL.md
.opencode/skills/query-optimize/SKILL.md
.opencode/skills/schema-migration/SKILL.md
.opencode/skills/sql-translate/SKILL.md
.opencode/skills/teach/SKILL.md
.opencode/skills/train/SKILL.md
.opencode/skills/training-status/SKILL.md
.opencode/skills/data-viz/SKILL.md
.opencode/skills/dbt-develop/SKILL.md
.opencode/skills/dbt-schema-verify/SKILL.md

Metadata

Files
0
Version
e27aeac
Hash
9de026d5
Indexed
2026-07-25 06:35

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 05:14
浙ICP备14020137号-1 $mapa de visitantes$