drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle-kit generate produces single-parent child instead of merge node from commutative leaves
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
1.0.0-rc.1
### What version of `drizzle-kit` are you using?
1.0.0-rc.1
### Other packages
_No response_
### Describe the Bug
I hit a similar issue to https://github.com/drizzle-team/drizzle-orm/issues/5504 - two commutative migrations were successfully applied, but a subsequent `drizzle-kit generate` dropped one of the leaf's updates and created a duplicate sql migration.
### Migration history:
```mermaid
flowchart TB
loud_piledriver["20260507223206_loud_piledriver"]
romantic_maginty["20260508222120_romantic_maginty
ADD COLUMN stage_ids"]
backfill["20260508222129_backfill_component_stage_ids
UPDATE … SET stage_ids = ARRAY[stage_id]"]
lovely_sharon["20260511173502_lovely_sharon_ventura
ALTER TYPE integration_type ADD VALUE 'microsoft_teams'"]
loud_piledriver --> romantic_maginty
romantic_maginty --> backfill
loud_piledriver --> lovely_sharon
```
The database state was fine: the `stage_ids` column was added and the enum value created.
### Issue
The next `drizzle-kit generate` failed to reconcile the two leaves and produced a **duplicate `ADD COLUMN stage_ids` migration**. The new migration only had a **single parent,** rather than correctly detecting the two commutative leaves
```
> drizzle-kit generate --config=./drizzle.config.ts
Reading config file '/home/runner/work/malleable/malleable/drizzle.config.ts'
[✓] Your SQL migration ➜ data/.migrations/20260512013627_mixed_amphibian/migration.sql 🚀
> drizzle-kit migrate --config=./drizzle.config.ts
Reading config file '/home/runner/work/malleable/malleable/drizzle.config.ts'
Non-commutative migrations detected Found 1 conflict across 2 migrations
data/.migrations/20260507223206_loud_piledriver
├── data/.migrations/20260508222120_romantic_maginty
│ data/.migrations/20260508222129_backfill_component_stage_ids
│ └─ ⚠ add_column: stage_ids on workflow_components_table table
└── data/.migrations/20260511173502_lovely_sharon_ventura
data/.migrations/20260512013627_mixed_amphibian
└─ ⚠ add_column: stage_ids on workflow_components_table table
```
```mermaid
flowchart TB
loud_piledriver["20260507223206_loud_piledriver"]
romantic_maginty["20260508222120_romantic_maginty
ADD COLUMN stage_ids"]
backfill["20260508222129_backfill_component_stage_ids
UPDATE … SET stage_ids = ARRAY[stage_id]"]
lovely_sharon["20260511173502_lovely_sharon_ventura
ALTER TYPE integration_type ADD VALUE 'microsoft_teams'"]
mixed_amphibian["20260512013627_mixed_amphibian
⚠ ADD COLUMN stage_ids (duplicate)"]
loud_piledriver --> romantic_maginty
romantic_maginty --> backfill
loud_piledriver --> lovely_sharon
lovely_sharon --> mixed_amphibian
style mixed_amphibian fill:#fee,stroke:#c00,stroke-width:2px
```
I resolved by manually editing the snapshot to have both `prevIds` and changing the sql to add `... IF NOT EXISTS` so it would no-op.
Happy to provide our migration history privately
Contributor guide
Assessment
This issue has not been assessed yet.