drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle-kit push (beta.22) tries to DROP TYPE all enum types after migration history reset
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe the Bug
After clearing stale migration tracking (`drizzle.__drizzle_migrations` table) and regenerating a fresh baseline migration, `drizzle-kit push` tries to `DROP TYPE` every enum type in the database — even though the schema files still define them via `pgEnum()` and columns still depend on them.
The ALTER TABLE statements from the diff apply successfully, but then Drizzle tries to drop each enum type alphabetically, failing with:
```
DROP TYPE "sex";
┌── query error: cannot drop type sex because other objects depend on it
```
After recreating that type manually and retrying, it moves to the next alphabetically (`user_role`, `application_status`, etc.) and fails again with the same error for each one.
### Expected Behavior
`drizzle-kit push` should recognize that enum types defined in the schema via `pgEnum()` are "owned" by the current schema — even when the migration tracking was reset. It should not try to drop types that are still referenced by columns.
### Actual Behavior
Push detects all existing enum types in the database as orphaned/unmanaged, generates `DROP TYPE ""` for each one, and fails because columns, defaults, or indexes depend on them.
### Reproduction Steps
1. Clear migration tracking: `DELETE FROM drizzle.__drizzle_migrations;`
2. Delete existing migration folder and regenerate: `drizzle-kit generate`
3. Register the baseline migration as applied
4. Run `drizzle-kit push` against a PostgreSQL database with existing tables that use enum types (e.g. via `pgEnum`)
### Versions
- `drizzle-kit`: 1.0.0-beta.22
- `drizzle-orm`: 1.0.0-beta.22
- Database: PostgreSQL (Neon)
### Related Issues
- #3305 — Related enum/push diff issues
- #4982 — Enum should be altered, not dropped
- #5156 — Push making multiple DROP CONSTRAINT NOT NULL
- #2389 — Enum label already exists on push
Contributor guide
Research direction
Start by reproducing the issue with PostgreSQL after clearing drizzle.__drizzle_migrations and regenerating a baseline, then inspect the generated DROP TYPE statements and enum diff handling. Done means drizzle-kit push preserves pgEnum types that remain defined and referenced, without failing on dependent columns, defaults, or indexes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100