Skip to content

drizzle-kit push does not add a check constraint to an existing table #439

Closed

Description

@imshashank

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.

Activity

  1. added
    help wanted
    p2 medium
    area: database
    size: small
    points: 2
    on Sep 7, 2026
  2. ayam04 commented on Sep 17, 2026

    @ayam04
    Contributor

    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.

  3. ayam04 commented on Sep 17, 2026

    @ayam04
    Contributor

    PR #477 is up: #477

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: databasehelp wantedp2 mediumpoints: 2size: small

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions