You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
drizzle-kit push does not add a check constraint to an existing table #439
area: databaseSchema, migrations, queries, seedhelp wantedWe would love a hand with this onep2 mediumWorth doing, not urgentpoints: 2Fibonacci estimate: 2size: smallA sitting. One file or two, the fix is written in the issue
Found while verifying #428. drizzle-kit push (0.31.10) includes a check() in CREATE TABLE when the table is new, but when the table already exists it does not diff check constraints, so the constraint is never added. Verified on 2026-09-07: pushing the #428 schema into a fresh database produced project_health_check and project_update_health_check; pushing the same schema into orbit_test_core, which already had both tables, produced neither. Migrations match the schema on CI does not compare check constraints either (CLAUDE.md lists columns, types, nullability, defaults, generated columns, keys, indexes, foreign keys and enum values), so nothing reports the gap.
The effect: every developer database and every test database that was pushed before #428 lands has no health constraint, while production, which is migrated through db:release, does. Tests that assert the constraint pass on CI (fresh databases) and fail locally (existing ones), which is exactly what happened.
What to do
Make packages/db/src/ensure-test-databases.ts drop and recreate the six base test databases before pushing, or apply pending migrations after the push, so a test database always matches a migrated one.
Have db:check-drift compare check constraints (pg_constraint with contype = 'c') against the declared schema, so this class of gap is reported rather than silent.
Document in docs/database-releases.md that db:push is not a substitute for a migration when a change adds a constraint to an existing table.
Small, and the second bullet is the one that matters long term.
Taking this one. Plan is the full list: drop and recreate the base test databases in ensure-test-databases.ts, teach db:check-drift to compare check constraints (pg_constraint with contype = 'c') against the declared schema, and add the db:push-versus-migration note to docs/database-releases.md.
It covers all three bullets: ensure-test-databases.ts drops and recreates the six base test databases before pushing, db:check-drift compares declared check() expressions against pg_constraint rows (contype = 'c') with name matching plus an expression fallback so a renamed constraint is not drift, and docs/database-releases.md documents the db:push limitation.
Validation: 12 focused tests pass; a database built from every committed migration reports zero drift across all 44 check constraints, and dropped, renamed, changed and undeclared checks are detected. Since db:release and the deploy guard share the catalog check, releases now verify constraint presence too. Details and the local-environment notes are in the PR body.
area: databaseSchema, migrations, queries, seedhelp wantedWe would love a hand with this onep2 mediumWorth doing, not urgentpoints: 2Fibonacci estimate: 2size: smallA sitting. One file or two, the fix is written in the issue
Activity
ayam04 commentedon Sep 17, 2026
Taking this one. Plan is the full list: drop and recreate the base test databases in
ensure-test-databases.ts, teachdb:check-driftto compare check constraints (pg_constraintwithcontype = 'c') against the declared schema, and add thedb:push-versus-migration note todocs/database-releases.md.ayam04 commentedon Sep 17, 2026
PR #477 is up: #477
It covers all three bullets:
ensure-test-databases.tsdrops and recreates the six base test databases before pushing,db:check-driftcompares declaredcheck()expressions againstpg_constraintrows (contype = 'c') with name matching plus an expression fallback so a renamed constraint is not drift, anddocs/database-releases.mddocuments thedb:pushlimitation.Validation: 12 focused tests pass; a database built from every committed migration reports zero drift across all 44 check constraints, and dropped, renamed, changed and undeclared checks are detected. Since
db:releaseand the deploy guard share the catalog check, releases now verify constraint presence too. Details and the local-environment notes are in the PR body.