Deterministic SQL risk review and multi-file migration planning, written in MoonBit.
.\scripts\acceptance.ps1moon run --target native cmd/main -- \
--format plan-json \
--require-full-coverage \
--schema examples/plan/schema.json \
examples/plan| ID | Severity | Rule |
|---|---|---|
| SQL001 | error | UPDATE/DELETE without a top-level WHERE or with an always-true predicate |
| SQL002 | error | Destructive DDL such as DROP TABLE, TRUNCATE, or DROP COLUMN |
| SQL003 | warning | Wildcard projection |
| SQL004 | warning | LIMIT without ORDER BY |
| SQL005 | warning | LIKE pattern starting with % or _ |
| SQL006 | warning | Comma-separated table list without explicit JOIN |
| SQL007 | warning | INSERT without a target-column list |
| SQL008 | warning | Added NOT NULL column without DEFAULT |
| SQL100 | warning | Malformed or unreachable SQLSentinel directive |
| SQL201 | warning | Destructive operation on a table referenced by another table |
| SQL202 | error | Dropping a column used by an index or foreign key |
| SQL301 | warning | In-place existing column type change |
| SQL302 | error | Migration references a missing schema object |
| SQL303 | warning | Foreign key without a supporting index prefix |
| SQL304 | warning | Table or column rename can break external callers |
| SQL305 | warning/error | Downstream query references a changed schema object |
moon run --target native cmd/main -- \
--format plan \
--schema examples/plan/schema.json \
examples/planmoon run --target native cmd/main -- \
--format impact-json \
--schema examples/plan/schema.json \
examples/plan \
--query examples/impact/queriesmoon run --target native cmd/main -- \
--format review-markdown \
--schema examples/plan/schema.json \
examples/plan \
--query examples/impact/queries- uses: Ljh684/sqlsentinel@v0.16.0
with:
paths: db/migrations
queries: services/**/*.sql
schema: .sqlsentinel/schema.json
format: review-sarif
sarif-file: sqlsentinel-review.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: sqlsentinel-review.sarifmoon update
moon run --target native cmd/main -- examples/safe_query.sqlmoon run --target native cmd/main -- \
--fail-on warning \
db/migrationsmoon run --target native cmd/main -- 'db/**/*.sql'
moon run --target native cmd/main -- 'queries/query_?.SQL'moon run --target native cmd/main -- \
--config examples/sqlsentinel.example.json{
"paths": ["db/**/*.sql", "queries/**/*.sql"],
"format": "text",
"failOn": "error",
"allowDestructive": false,
"styleChecks": true,
"ignore": ["SQL008"],
"base": "origin/main...HEAD",
"dialect": "postgres",
"schema": "schema.json",
"baseline": ".sqlsentinel/baseline.json",
"severityOverrides": {
"SQL008": "error",
"SQL003": "info"
},
"queries": ["services/**/*.sql"]
}{
"tables": [
{
"name": "users",
"columns": [
{"name": "id", "nullable": false},
{"name": "email", "nullable": false}
],
"indexes": [
{"name": "users_email", "columns": ["email"], "unique": true}
]
},
{
"name": "orders",
"columns": [
{"name": "id", "nullable": false},
{"name": "user_id", "nullable": false}
],
"foreignKeys": [
{
"name": "orders_user_fk",
"columns": ["user_id"],
"references": {"table": "users", "columns": ["id"]}
}
]
}
]
}moon run --target native cmd/main -- \
--schema examples/schema.json \
examples/schema_risks.sqlmoon run --target native cmd/main -- \
--write-baseline .sqlsentinel/baseline.json \
db/migrations
moon run --target native cmd/main -- \
--baseline .sqlsentinel/baseline.json \
--fail-on error \
db/migrationsmoon run --target native cmd/main -- \
--severity SQL008=error,SQL003=info \
db/migrationsbash scripts/build-web.sh
python3 -m http.server 8080 --directory web/distmoon run --target native cmd/main -- \
--format markdown \
--fail-on never \
db/migrations > sql-review.mdmoon run --target native cmd/main -- \
--format sarif \
--fail-on never \
db/migrations > sqlsentinel.sarifmoon run --target native cmd/main -- \
--format github \
db/migrationsmoon run --target native cmd/main -- --changed
moon run --target native cmd/main -- \
--changed \
--base origin/main...HEADmoon run --target native cmd/main -- \
--format json \
--fail-on never \
--sql "UPDATE users SET active = false;"sqlsentinel [options] <file-or-directory>...
sqlsentinel --sql "<SQL text>"-- sqlsentinel: ignore SQL003
SELECT * FROM legacy_export_view;
SELECT * FROM users; -- SQL003 is still reported here/* sqlsentinel: ignore SQL003, SQL004 */
SELECT * FROM legacy_export_view LIMIT 100;let report = @sqlsentinel.scan_sql(
"DELETE FROM users WHERE disabled_at IS NOT NULL;",
)
if report.should_fail(@sqlsentinel.FailLevel::Warning) {
println(@sqlsentinel.report_to_markdown(report))
}jobs:
sql-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Ljh684/sqlsentinel@v0.16.0
with:
paths: |
db/**/*.sql
queries/**
fail-on: errormoon check --target native
moon test --target native
moon fmt --check
moon run --target native cmd/main -- examples/safe_migration.sqltypes.mbt public models and rule catalog
lexer.mbt SQL-aware tokenization and statement splitting
analyzer.mbt structural checks and report aggregation
schema_analyzer.mbt
schema-aware cross-object checks
migration_analyzer.mbt
evolving multi-file schema and migration plan analysis
impact_analyzer.mbt
migration-to-query dependency and impact analysis
schema/ shared JSON schema parser and validation
render.mbt text, JSON, Markdown, and SARIF renderers
cmd/main/ native CLI, baseline loading, and Git integration
action.yml reusable composite GitHub Action
examples/ safe and intentionally risky SQL files
docs/ project plan and review notespub(all) struct Finding {
rule_id : String
title : String
severity : Severity
message : String
suggestion : String
statement_index : Int
line : Int
column : Int
evidence : String
fingerprint : String
}pub(all) struct ImpactAnalysis {
references : Array[QueryReference]
findings : Array[MigrationFinding]
impacted_tables : Array[String]
impacted_files : Array[String]
error_count : Int
warning_count : Int
info_count : Int
migration_coverage : MigrationCoverage
}pub(all) struct MigrationAnalysis {
changes : Array[SchemaChange]
findings : Array[MigrationFinding]
tables_before : Array[String]
tables_after : Array[String]
affected_tables : Array[String]
breaking_changes : Int
error_count : Int
warning_count : Int
info_count : Int
coverage : MigrationCoverage
}pub(all) struct MigrationCoverage {
statement_count : Int
analyzed_count : Int
ignored_count : Int
traces : Array[StatementTrace]
}pub(all) struct QueryReference {
change_kind : SchemaChangeKind
table_name : String
column_name : String
path : String
line : Int
statement_index : Int
evidence : String
}pub(all) struct Report {
statement_count : Int
findings : Array[Finding]
error_count : Int
warning_count : Int
info_count : Int
suppressed_count : Int
suppressions : Array[SuppressedRule]
dialect : Dialect
schema_enabled : Bool
baseline_enabled : Bool
baseline_suppressed_count : Int
severity_overrides : Array[SeverityOverride]
}fn Report::from_parts(statement_count : Int, findings : Array[Finding], suppressed_count : Int, suppressions : Array[SuppressedRule], dialect : Dialect, schema_enabled : Bool, baseline_enabled? : Bool, baseline_suppressed_count? : Int, severity_overrides? : Array[SeverityOverride]) -> Reportpub(all) struct RuleDefinition {
id : String
title : String
severity : Severity
rationale : String
remediation : String
}pub(all) struct ScanOptions {
allow_destructive : Bool
style_checks : Bool
ignored_rules : Array[String]
dialect : Dialect
schema : SchemaCatalog
severity_overrides : Array[SeverityOverride]
} derive(Eq)fn ScanOptions::new(allow_destructive? : Bool, style_checks? : Bool, ignored_rules? : Array[String], dialect? : Dialect, schema? : SchemaCatalog, severity_overrides? : Array[SeverityOverride]) -> ScanOptionsfn SchemaCatalog::column_is_referenced(self : SchemaCatalog, table_name : String, column_name : String) -> Boolpub(all) struct SchemaChange {
kind : SchemaChangeKind
table_name : String
column_name : String
detail : String
path : String
line : Int
statement_index : Int
}pub(all) enum SchemaChangeKind {
CreateTable
DropTable
AddColumn
DropColumn
AlterColumnType
RenameTable
RenameColumn
CreateIndex
AddForeignKey
} derive(Eq)pub(all) struct SchemaTable {
name : String
columns : Array[SchemaColumn]
indexes : Array[SchemaIndex]
foreign_keys : Array[SchemaForeignKey]
} derive(Eq)fn StatementAnalysisStatus::not_equal(x : StatementAnalysisStatus, y : StatementAnalysisStatus) -> Boolpub(all) struct StatementTrace {
path : String
statement_index : Int
line : Int
end_line : Int
token_count : Int
kind : String
status : StatementAnalysisStatus
reason : String
}pub(all) struct SuppressedRule {
rule_id : String
count : Int
}fn analysis_capabilities_markdown() -> Stringfn analyze_change_impact(migrations : Array[MigrationInput], queries : Array[MigrationInput], options : ScanOptions) -> ImpactAnalysisfn review_packet_to_json(files : Array[FileReport], migration : MigrationAnalysis, impact : ImpactAnalysis?) -> Stringfn review_packet_to_markdown(files : Array[FileReport], migration : MigrationAnalysis, impact : ImpactAnalysis?) -> Stringfn review_packet_to_text(files : Array[FileReport], migration : MigrationAnalysis, impact : ImpactAnalysis?) -> Stringfn review_sarif_to_string(files : Array[FileReport], migration : MigrationAnalysis, impact : ImpactAnalysis?) -> Stringfn rule_catalog_markdown() -> StringInstall
Download zipDeterministic SQL risk review and multi-file migration planning, written in MoonBit.