Skip to Content
Database

Migrations

Scan SQL migrations for changes that lose data or break running code.

Usage

npx signet-db-check                      # ./drizzle and ./migrations
npx signet-db-check drizzle/0007_add_status.sql

In CI, check only the migrations a change adds:

signet-db-check $(git diff --name-only --diff-filter=A origin/main -- 'drizzle/*.sql')

From code:

import { checkMigrationSql, formatIssues } from "@dapplelight/signet-db/migrations"
import { sql } from "drizzle-orm"

const issues = checkMigrationSql(sql, "drizzle/0007_add_status.sql")
if (issues.length) console.error(formatIssues(issues))

API

ExportWhat it does
checkMigrationSql(sql, file?)Issues found in one migration's SQL.
formatIssues(issues)One readable entry per issue: file:line kind message.
MigrationIssue{ kind, file, line, statement, message }.
MigrationIssueKindThe kinds below.
signet-db-check [paths...]CLI. Exits 1 if anything is flagged, 2 if a path is missing.
KindFlags
drop-tableDROP TABLE
drop-columnALTER TABLE ... DROP COLUMN
renameRenaming a table or column
not-null-without-defaultAdding NOT NULL with no DEFAULT, or SET NOT NULL

Works on drizzle-kit output (--> statement-breakpoint) and plain ;-separated SQL. SQLite table rebuilds (__new_x copied, renamed to x) are not flagged.

Examples

Accept a deliberate change

Put the marker inside the statement. Use all to accept every kind.

-- signet-allow: drop-column
ALTER TABLE `invoices` DROP COLUMN `legacy_ref`;