drizzle-team / drizzle-team/drizzle-orm

[BUG]: "drizzle-kit generate" does not emit enum migration when pgEnum is not exported

Open
#5,174 8 comments 1 reaction 0 assignees View on GitHub
docs docs/undocumented enhancement
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-beta.6-4414a19

### What version of `drizzle-kit` are you using?

1.0.0-beta.6-4414a19

### Other packages

drizzle-typebox@1.0.0-beta.6-4414a19

### Describe the Bug

When using pgEnum in the schema, drizzle-kit generate fails to include the enum definition in the generated migration.sql file unless the enum is explicitly exported.

**Actual result**

The generated migration.sql does **NOT** include the enum creation:
`CREATE TYPE "provider" AS ENUM('credentials', 'github', 'google');--> statement-breakpoint`

**Expected result**

The enum should be included in the migration, even when it is not exported, since it is defined and used in the same file.

**Workaround**

Exporting the enum fixes the issue:
```
// before
const providerEnum = pgEnum('provider', [
Provider.CREDENTIALS,
Provider.GITHUB,
Provider.GOOGLE,
]);

// after
export const providerEnum = pgEnum('provider', [
Provider.CREDENTIALS,
Provider.GITHUB,
Provider.GOOGLE,
]);
```

**After exporting the enum:**

The generated migration.sql now correctly includes:
`CREATE TYPE "provider" AS ENUM('credentials', 'github', 'google');--> statement-breakpoint`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.