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
- Unsafe ALTER TABLE – column adds without defaults, type changes that lose data, NOT NULL added to populated columns
- DROP operations –
DROP TABLE/DROP COLUMNwithout an explicit migration-roll-forward path - Missing idempotency – DDL outside the migrator that fails when it runs again
- Foreign-key misuse –
INSERT OR REPLACEon 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) - Batch inserts outside a transaction – insert loops that run outside
db.write { }ordb.inTransaction { }and pay one disk sync per row (code insideregisterMigrationalready runs in a transaction, so it needs noBEGIN) - 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
Related Agent
- database-schema-auditor – The agent that powers this command