orm-lens migration-risk --path . also reads migrations kept as plain SQL, so Node, Go, Java and Supabase projects get the same review as Django and Alembic ones. Like the other rules it is static: the files are read as text, never run, and no database is touched. Usage, output formats and CI semantics are those of the Django migration rules: exit code 1 on critical findings, --severity critical|warning|info|all (default critical), --format text|json|sarif|github|gitlab. Findings carry the tool in app, the migration in migration, the table in model and the column in field.
| Tool | What is read | Order |
|---|---|---|
| Prisma | migrations/*/migration.sql next to migration_lock.toml |
folder name |
| Drizzle | drizzle-kit 0.x: the .sql files listed in meta/_journal.json; 1.x: <out>/*/migration.sql beside a snapshot.json |
journal idx, or folder name |
| Supabase | supabase/migrations/*.sql |
file name |
| Flyway | V<version>__<name>.sql under a migration or migrations directory, subdirectories included (repeatable R__ files are skipped) |
version |
| golang-migrate, and tools with the same naming (sqlx, morph) | *.up.sql (*.down.sql is skipped) |
leading number |
| goose | .sql files with -- +goose Up, up to -- +goose Down |
leading number |
| dbmate | .sql files with -- migrate:up, up to -- migrate:down |
leading number |
Other .sql files, such as schema.sql or seed data, are not migrations and are not read, except in supabase/migrations, where every .sql file is a migration. Neither are node_modules, vendor, dist, build, target and hidden directories.
The MCP server accepts a workspace with SQL migrations and no Django or SQLAlchemy project when one of these files is at most four directories down: migration_lock.toml, meta/_journal.json, a migration.sql beside a snapshot.json, a Flyway or *.up.sql file, .sql files in a migration or migrations directory, or a numbered .sql file with a goose (-- +goose Up) or dbmate (-- migrate:up) marker. For that marker only the first 20 numbered files of a directory are opened, and only their first 64 KiB. If yours is deeper, or its marker is further in, point workspace_root at the migrations directory or a directory named migrations.
Prisma records the database in migration_lock.toml and Drizzle in its journal (0.x) or the newest snapshot (1.x). For the other tools the scanned root or a directory below it named mysql, mariadb, sqlite or postgres decides, as in Mattermost’s db/migrations/mysql/; the directories a project is checked out under don’t count. Otherwise the SQL decides, outside comments and strings: backquoted names, ENGINE=, AUTO_INCREMENT or MODIFY COLUMN mean MySQL, AUTOINCREMENT or PRAGMA mean SQLite, and the dialect with the most of its own constructs wins. A Flyway folder named for a database inside a location (db/migration/mysql) gives its dialect to the history it joins, or stays a history of its own when that one has another. PostgreSQL is assumed when nothing tells.
CONCURRENTLY and NOT VALID do not exist in SQL Server, where the counterparts are CREATE INDEX ... WITH (ONLINE = ON) (Enterprise edition and Azure SQL) and ALTER TABLE ... WITH NOCHECK ADD CONSTRAINT, checked later with WITH CHECK CHECK CONSTRAINT.MODIFY and CHANGE copy the table and are reported as type changes.Checked against 2539 real migrations: Prisma in Cal.com, Documenso, Umami, Langfuse and Trigger.dev, Drizzle in lobe-chat (PostgreSQL) and openstatus (SQLite). Another 425 drizzle-kit 1.x migrations: hollo, Hackers’ Pub and Zipline (PostgreSQL), Zerobyte, Headplane, LNReader, holocron and a Cloudflare Workers SaaS template (SQLite).
new_User is created, filled, and renamed to User). Renaming an existing table does not make it new: the lock rules still apply to it. Nobody uses a new table yet, so the lock rules skip it. If rows are put into it (INSERT, COPY ... FROM, CREATE TABLE ... AS SELECT or AS EXECUTE without WITH NO DATA, SELECT ... INTO) before a NOT NULL column is added, that column is still critical.CREATE TABLE IF NOT EXISTS of a table an earlier migration of the history created, and none dropped since, does nothing, so the table is not new. After a drop it creates the table again, empty. Drizzle writes every new table this way.scratch.users is not users); public, dbo and main are the default schema, so "public"."User" is "User".ALTER TABLE t RENAME TO t_old) and created again in the same migration is rebuilt, not dropped.DELETE FROM without WHERE or a TRUNCATE of the table earlier in the same migration may have emptied it. A NOT NULL column added after one is a warning, not a certain critical. A DELETE with a WHERE may leave rows, so it changes nothing.$$ bodies, so SQL inside a function, a COMMENT ON or a default value is never mistaken for a migration step. Drizzle’s DO $$ BEGIN ... EXCEPTION ... END $$ around foreign keys is read through.Operation: ADD COLUMN · Severity: critical · Confidence: high · populated tables, PostgreSQL
Adds a NOT NULL column (or a primary key) with no DEFAULT. Existing rows get NULL, so the ALTER TABLE fails. Identity, generated and serial columns are filled by the database and are exempt.
-- Prisma generates this, with a warning that it fails on a table that has rows
ALTER TABLE "Booking" ADD COLUMN "uid" TEXT NOT NULL;
Prisma itself warns about this case in the migration it generates. When the authors edit the migration to add the column nullable, backfill it and then set NOT NULL, or to give it a default, this rule stays silent and the SET NOT NULL step is reported instead. It also catches a case Prisma words differently: a column dropped and added again as NOT NULL because its type changed.
Mitigation: Add the column nullable, backfill it, then set NOT NULL in a later migration. Or give it a DEFAULT.
Operation: CREATE INDEX · Severity: warning · Confidence: medium · populated tables, PostgreSQL
CREATE INDEX without CONCURRENTLY blocks writes to the table for the whole build.
Mitigation: CREATE INDEX CONCURRENTLY, in a migration of its own: it cannot run inside a transaction.
Operation: ALTER COLUMN ... SET NOT NULL · Severity: warning · Confidence: medium · populated tables, PostgreSQL
PostgreSQL scans the whole table under an exclusive lock to verify there are no NULLs, and the ALTER fails if any row still has one.
Mitigation: Backfill first. On large tables add CHECK (col IS NOT NULL) NOT VALID, VALIDATE it, then set NOT NULL.
Operation: ALTER COLUMN ... TYPE, MODIFY, CHANGE · Severity: warning · Confidence: medium · populated tables, not SQLite
Most type changes rewrite the table under an exclusive lock. Some don’t (a longer varchar, varchar to text), but the migration alone doesn’t say what the old type was.
Mitigation: Add a column of the new type and keep it in step with a trigger on the old one; backfill with batched UPDATE … SET new = old (with the cast the migration uses), which reads and writes each row under its lock so no newer write is overwritten; move reads and writes to the new column, then drop the old one once no instance of the previous release is left.
Operation: RENAME COLUMN, or CHANGE old new · Severity: warning · Confidence: medium · populated tables
Code still running from the previous release keeps using the old name until every instance is replaced. The finding’s field is the new name, and the description names the old one.
Mitigation: Add the new column and keep it in step with a trigger on the old one; backfill with batched UPDATE … SET new = old, which reads and writes each row under its lock; move reads and writes to the new column, then drop the old one once no instance of the previous release is left.
Operation: ALTER TABLE ... RENAME TO, RENAME TABLE · Severity: warning · Confidence: medium · populated tables
Code still running from the previous release keeps querying the old name.
Mitigation: Create the new table and mirror every insert, update and delete on the old one into it with a trigger, in the same transaction; backfill in batches that lock the rows they copy (SELECT … FOR SHARE) and skip rows already there, so an update or delete waits for the batch and is then mirrored; move reads and writes to the new table and point foreign keys that reference the old one at it, then drop the old one once no instance of the previous release is left.
Operation: DROP COLUMN · Severity: warning · Confidence: medium · populated tables
The previous release still selects the column until every instance is replaced.
Mitigation: Remove the column from the code and deploy first; drop it in a later release.
Operation: DROP TABLE · Severity: warning · Confidence: medium · populated tables
The previous release still queries the table, so every remaining instance fails until it is replaced.
Mitigation: Remove the table from the code and deploy first; drop it in a later release.
Operation: ADD CONSTRAINT ... UNIQUE / PRIMARY KEY / EXCLUDE · Severity: warning · Confidence: medium · populated tables, not SQLite
The index is built while writes are blocked, and existing duplicates make it fail. ADD CONSTRAINT ... USING INDEX reuses an index that is already built and is not reported.
Mitigation: For UNIQUE and PRIMARY KEY, CREATE UNIQUE INDEX CONCURRENTLY first, then ADD CONSTRAINT ... USING INDEX. For a primary key, set NOT NULL on its columns first (backfilled and checked as in sql_set_not_null_scans_table): otherwise attaching the index scans the table under the lock. USING INDEX does not work for EXCLUDE: its index is always built under the lock, so add it while the table is small or writes can wait.
Operation: ADD CONSTRAINT ... FOREIGN KEY · Severity: warning · Confidence: medium · populated tables, not SQLite
Every existing row is checked while both tables are locked against writes. A constraint added NOT VALID is not reported.
Mitigation: Add it NOT VALID, then VALIDATE CONSTRAINT in a separate migration.
Operation: ADD CONSTRAINT ... CHECK · Severity: warning · Confidence: medium · populated tables, not SQLite
Every existing row is checked under an exclusive lock. A constraint added NOT VALID is not reported.
Mitigation: Add it NOT VALID, then VALIDATE CONSTRAINT in a separate migration.