@@ -469,6 +469,45 @@ model Group {
469469 // consolidation should map them back to the original shared Status enum
470470 expect ( getSchema ( workDir ) ) . toEqual ( schema ) ;
471471 } ) ;
472+
473+ it ( 'should consolidate per-column enums with --always-map without stale @@map' , async ( ) => {
474+ // This test targets a bug where consolidateEnums renames keepEnum.name
475+ // to oldEnum.name but leaves the synthetic @@map attribute added by
476+ // syncEnums, so getDbName(keepEnum) still returns the old mapped name
477+ // (e.g., 'UserStatus') instead of the consolidated name ('Status'),
478+ // preventing matching in the downstream delete/add enum logic.
479+ const { workDir } = await createProject (
480+ `enum Status {
481+ ACTIVE
482+ INACTIVE
483+ SUSPENDED
484+ }
485+
486+ model User {
487+ id Int @id @default(autoincrement())
488+ status Status @default(ACTIVE)
489+ }
490+
491+ model Group {
492+ id Int @id @default(autoincrement())
493+ status Status @default(ACTIVE)
494+ }` ,
495+ ) ;
496+ runCli ( 'db push' , workDir ) ;
497+
498+ runCli ( 'db pull --indent 4 --always-map' , workDir ) ;
499+
500+ const pulledSchema = getSchema ( workDir ) ;
501+
502+ // The consolidated enum should be named Status, not UserStatus/GroupStatus
503+ expect ( pulledSchema ) . toContain ( 'enum Status' ) ;
504+ expect ( pulledSchema ) . not . toContain ( 'enum UserStatus' ) ;
505+ expect ( pulledSchema ) . not . toContain ( 'enum GroupStatus' ) ;
506+
507+ // There should be no stale @@map referencing the synthetic per-column name
508+ expect ( pulledSchema ) . not . toMatch ( / @ @ m a p \( [ ' " ] U s e r S t a t u s [ ' " ] \) / ) ;
509+ expect ( pulledSchema ) . not . toMatch ( / @ @ m a p \( [ ' " ] G r o u p S t a t u s [ ' " ] \) / ) ;
510+ } ) ;
472511 } ) ;
473512
474513 describe ( 'Pull should preserve triple-slash comments on enums' , ( ) => {
0 commit comments