Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 69e23b2

Browse files
committed
fix: address PR comments
1 parent 39a04eb commit 69e23b2

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/cli/src/actions/pull/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,15 @@ export function consolidateEnums({
638638
// Rename the kept enum to match the old shared name
639639
keepEnum.name = oldEnum.name;
640640

641+
// Replace keepEnum's attributes with those from the old enum so that
642+
// any synthetic @@map added by syncEnums is removed and getDbName(keepEnum)
643+
// reflects the consolidated name rather than the stale per-column name.
644+
// Shallow-copy and re-parent so AST $container pointers reference keepEnum.
645+
keepEnum.attributes = oldEnum.attributes.map((attr) => {
646+
const copy = { ...attr, $container: keepEnum };
647+
return copy;
648+
});
649+
641650
// Remove duplicate enums from newModel
642651
for (let i = 1; i < newEnumsGroup.length; i++) {
643652
const idx = newModel.declarations.indexOf(newEnumsGroup[i]!);

packages/cli/test/db/pull.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/@@map\(['"]UserStatus['"]\)/);
509+
expect(pulledSchema).not.toMatch(/@@map\(['"]GroupStatus['"]\)/);
510+
});
472511
});
473512

474513
describe('Pull should preserve triple-slash comments on enums', () => {

0 commit comments

Comments
 (0)