Skip to content

[BUG]: drizzle-kit generate produces single-parent child instead of merge node from commutative leaves #5764

@aarongut

Description

@aarongut

Report hasn't been filed before.

  • 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 #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:

flowchart TB
    loud_piledriver["20260507223206_loud_piledriver"]
    romantic_maginty["20260508222120_romantic_maginty<br/><i>ADD COLUMN stage_ids</i>"]
    backfill["20260508222129_backfill_component_stage_ids<br/><i>UPDATE … SET stage_ids = ARRAY[stage_id]</i>"]
    lovely_sharon["20260511173502_lovely_sharon_ventura<br/><i>ALTER TYPE integration_type ADD VALUE 'microsoft_teams'</i>"]

    loud_piledriver --> romantic_maginty
    romantic_maginty --> backfill
    loud_piledriver --> lovely_sharon
Loading

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
flowchart TB
      loud_piledriver["20260507223206_loud_piledriver"]
      romantic_maginty["20260508222120_romantic_maginty<br/><i>ADD COLUMN stage_ids</i>"]
      backfill["20260508222129_backfill_component_stage_ids<br/><i>UPDATE … SET stage_ids = ARRAY[stage_id]</i>"]
      lovely_sharon["20260511173502_lovely_sharon_ventura<br/><i>ALTER TYPE integration_type ADD VALUE 'microsoft_teams'</i>"]
      mixed_amphibian["20260512013627_mixed_amphibian<br/><b>⚠ ADD COLUMN stage_ids (duplicate)</b>"]

      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
Loading

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions