drizzle-team / drizzle-team/drizzle-orm

[BUG]: Migration tries to drop enum when it should be just altered

Open
#4,982 2 comments 3 reactions 0 assignees View on GitHub
db/postgres 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?

0.44.2

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

0.31.4

### Other packages

_No response_

### Describe the Bug

I renamed the values of a AppStatus enum:

```js
export enum AppStatus {
IN_REVIEW = "IN_REVIEW", //renamed from "PENDING"
ACTIVE = "ACTIVE",
PAUSED = "PAUSED", // renamed from "INACTIVE"
BANNED = "BANNED",
}

export const appStatusEnum = pgEnum("app_status", AppStatus);

export const users = pgTable("users", {
id: uuid("id").primaryKey(),
appStatus: appStatusEnum("app_status").default(AppStatus.IN_REVIEW).notNull(),
appStatusNotes: text("app_status_notes"),
});
```

And since the users table is dependent, and there are rows already with the old values, I was expecting the migration SQL to be just

```sql
ALTER TYPE public.app_status RENAME VALUE 'PENDING' TO 'IN_REVIEW';
ALTER TYPE public.app_status RENAME VALUE 'INACTIVE' TO 'PAUSED';
```

But this is the script generated::

```sql
DROP TYPE "public"."app_status";
CREATE TYPE "public"."app_status" AS ENUM('IN_REVIEW', 'ACTIVE', 'PAUSED', 'BANNED');
ALTER TABLE "users" ALTER COLUMN "app_status" SET DEFAULT 'IN_REVIEW';
```

It doesn't run because `column app_status of table users depends on type app_status`. Can't it know about that dependency beforehand to generate a valid script?

Is this a skill issue on my end and I'm missing some preservation config, or is the ORM at fault?

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.