Skip to content

audit-database-schema ​

Scan database migration and schema-evolution code for patterns that risk data loss or migration crashes.

What This Command Does ​

Launches the database-schema-auditor agent to flag dangerous SQL patterns in migration files — destructive operations, schema code outside the migrator that cannot run twice, and foreign-key misuse that breaks under concurrent access.

What It Checks ​

  1. Unsafe ALTER TABLE – column adds without defaults, type changes that lose data, NOT NULL added to populated columns
  2. DROP operations – DROP TABLE/DROP COLUMN without an explicit migration-roll-forward path
  3. Missing idempotency – DDL outside the migrator that fails when it runs again
  4. Foreign-key misuse – INSERT OR REPLACE on tables whose children cascade-delete, a foreign key added to an existing table without an orphan check, and enforcement switched off (PRAGMA foreign_keys = OFF, foreignKeysEnabled = false)
  5. Batch inserts outside a transaction – insert loops that run outside db.write { } or db.inTransaction { } and pay one disk sync per row (code inside registerMigration already runs in a transaction, so it needs no BEGIN)
  6. Merged migrations – GRDB merging: registrations that skip schema steps for partly upgraded databases, rely on GRDB 7.8.0, or check migration state before migrating

Released under the MIT License