Skip to content

@sbtools/plugin-migration-audit

npm

Plugin that compares migration files on disk with app_migrations.schema_migrations. Detects drift, missing files, pending migrations. Reports via CLI, JSON, HTML, and Backend Atlas. Read-only — makes zero schema modifications.

Quick Start

bash
npm install @sbtools/plugin-migration-audit

Add to config: { "path": "@sbtools/plugin-migration-audit" }

bash
# Run audit (DB optional — disk-only if unreachable)
npx sbt migration-audit
# → docs/migration-audit.html
# → CLI summary + open in browser
$ npx sbt migration-audit

Migration Audit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Migrations Dir  supabase/migrations
Database        Connected
Tracking Table  Exists

Total: 63  Applied: 63  Pending: 0  Missing: 0

Migrations:
  APPLIED  20251218135835_create_users.sql              (2026-02-12T11:43:40)
  APPLIED  20251218135847_add_organizations.sql         (2026-02-12T11:43:40)
  APPLIED  20251224154957_create_subscriptions.sql      (2026-02-12T11:43:40)
  ...

✓ HTML report → docs/migration-audit.html
✓ Detail pages → docs/migration-audit/<slug>.html

Each migration has a detail page with SQL viewer, parsed operations, risk flags, and touched objects. Links from the main report and Backend Atlas cards.

Commands

CommandDescription
migration-auditCLI summary + HTML report + open browser
migration-audit --jsonOutput raw audit JSON
migration-audit --htmlGenerate HTML only
migration-audit --no-openSkip opening browser

Migrations dashboard pageMigrations page — audit summary, inventory table with applied/pending/missing filters

Issues Detected

CodeSeverityDescription
MISSING_FILEerrorApplied in DB but file missing on disk
PENDING_MIGRATIONwarningFiles not yet applied
NO_TRACKING_TABLEwarningapp_migrations.schema_migrations missing
ORDERING_GAPwarningApplied out of chronological order
TIMESTAMP_PARSE_FAILUREinfoNon-standard filename (no YYYYMMDDHHMMSS prefix)
EMPTY_MIGRATIONinfo0-byte migration files

Artifact

Produces migration.analysis v1.0.0. Includes per-migration sqlAnalysis (operations, touched objects, risk flags, confidence). Consumed by migration-studio for schema fallback and migrations context.

Configuration

No config fields required. Uses paths.migrations and paths.docsOutput. Database optional — uses DATABASE_URL / SUPABASE_DB_URL / POSTGRES_URL when available.