Skip to content

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

@devguilhermy

Description

@devguilhermy

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?

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:

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

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::

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions