Skip to content

[BUG]: drizzle-kit commutative migrations takes only last leaf migration into account #5504

@amitbeck

Description

@amitbeck

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-beta.18-7eb39f0

What version of drizzle-kit are you using?

1.0.0-beta.18-7eb39f0

Other packages

No response

Describe the Bug

This is my current migration history:

flowchart TB                                                                                                                              
    ROOT["ROOT"] --> low_ravenous["20260126122507_low_ravenous"]                                                                            
    low_ravenous --> ancient_lord_hawal["20260129131205_ancient_lord_hawal"]                                                                
    low_ravenous --> lean_katie_power["20260201113457_lean_katie_power"]                                                                    
    ancient_lord_hawal --> harsh_skreet["20260203160209_harsh_skreet"]                                                                      
    lean_katie_power --> harsh_skreet                                                                                                       
    harsh_skreet --> serious_sue_storm["20260204104433_serious_sue_storm"]                                                                  
    serious_sue_storm --> jazzy_ikaris["20260216143830_jazzy_ikaris"]                                                                       
    jazzy_ikaris --> sour_night_nurse["20260222123946_sour_night_nurse"]                                                                    
    sour_night_nurse --> flippant_jamie_braddock["20260301135635_flippant_jamie_braddock"]
    flippant_jamie_braddock --> safe_hercules["20260302170932_safe_hercules"]                                                               
    safe_hercules --> minor_banshee["20260302171513_minor_banshee"]                                                                         
    minor_banshee --> concerned_shocker["20260303133920_concerned_shocker"]                                                                 
    concerned_shocker --> blushing_kid_colt["20260303134830_blushing_kid_colt"]                                                             
    blushing_kid_colt --> dazzling_tyger_tiger["20260308115822_dazzling_tyger_tiger"]                                                       
    blushing_kid_colt --> complex_groot["20260308154317_complex_groot"]
Loading

As you can see, I have 2 leaf migrations sharing the same parent:

  1. dazzling_tyger_tiger has renamed an enum, and moved the column that used this enum from one table A to another table B.
  2. complex_groot has added another column to table B.

Both migrations were created by 2 different team members in their own feature branches, but complex_groot was added later.

For some reason, when running drizzle-kit generate to generate a migration for new changes, only the latter migration, complex_groot, is taken into account when diffing the snapshot against the ORM schema - Drizzle Kit prompts me to ask whether the aforementioned enum was renamed or created, but this change was already done in dazzling_tyger_tiger, the first leaf migration.

I tried running drizzle-kit generate using both v1.0.0-beta.11 (which we've been using thus far) and v1.0.0-beta.18 (the latest version, which includes commutative migrations), but both attempts resulted in this issue.

My workaround was to make complex_groot a child of dazzling_tyger_tiger - update its prevIds and ddl in snapshot.json:

flowchart TB                                                                                                                              
    ROOT --> low_ravenous["20260126122507_low_ravenous"]                                                                                  
    low_ravenous --> ancient_lord_hawal["20260129131205_ancient_lord_hawal"]                                                                
    low_ravenous --> lean_katie_power["20260201113457_lean_katie_power"]                                                                    
    ancient_lord_hawal --> harsh_skreet["20260203160209_harsh_skreet"]                                                                      
    lean_katie_power --> harsh_skreet                                                                                                       
    harsh_skreet --> serious_sue_storm["20260204104433_serious_sue_storm"]                                                                  
    serious_sue_storm --> jazzy_ikaris["20260216143830_jazzy_ikaris"]                                                                       
    jazzy_ikaris --> sour_night_nurse["20260222123946_sour_night_nurse"]                                                                    
    sour_night_nurse --> flippant_jamie_braddock["20260301135635_flippant_jamie_braddock"]                                                  
    flippant_jamie_braddock --> safe_hercules["20260302170932_safe_hercules"]                                                               
    safe_hercules --> minor_banshee["20260302171513_minor_banshee"]                                                                         
    minor_banshee --> concerned_shocker["20260303133920_concerned_shocker"]                                                                 
    concerned_shocker --> blushing_kid_colt["20260303134830_blushing_kid_colt"]                                                             
    blushing_kid_colt --> dazzling_tyger_tiger["20260308115822_dazzling_tyger_tiger"]                                                       
    dazzling_tyger_tiger --> complex_groot["20260308154317_complex_groot"]
Loading

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