Drizzle not creating enum

Hey guys, I am using drizzle in my project with postgres. I create a new enum(with pgenum) but the generate sql is missing the definition of the enum.
const status = pgEnum('status', [
'created',
'generating',
'generated',
'error',
]);
const status = pgEnum('status', [
'created',
'generating',
'generated',
'error',
]);
and using this as status: status().notNull().default('created') and here's the generated sql
CREATE TABLE "curriculums" (
"id" varchar PRIMARY KEY NOT NULL,
"user_id" varchar NOT NULL,
"language_id" varchar NOT NULL,
"created_at" varchar DEFAULT now() NOT NULL,
"status" "status" DEFAULT 'created' NOT NULL,
"reason" varchar DEFAULT '' NOT NULL,
"knowledge" varchar DEFAULT '' NOT NULL
);
CREATE TABLE "curriculums" (
"id" varchar PRIMARY KEY NOT NULL,
"user_id" varchar NOT NULL,
"language_id" varchar NOT NULL,
"created_at" varchar DEFAULT now() NOT NULL,
"status" "status" DEFAULT 'created' NOT NULL,
"reason" varchar DEFAULT '' NOT NULL,
"knowledge" varchar DEFAULT '' NOT NULL
);
there's no definition of enum
12 Replies
TOSL
TOSL2mo ago
you have to export everything Drizzle doesn't know you created an enum because you didn't export it
Phantom
PhantomOP2mo ago
I did export it
Mario564
Mario5642mo ago
@Phantom Assuming you're already exporting the status enum, in what file is that enum present in and what's the schema path in your Drizzle config file?
TOSL
TOSL2mo ago
Okay. What you added here just says const status so that was the quickest solution. If you have that in the actual file, then I don't think you actually have an issue. Drizzle would create the enum and then create the table.
Phantom
PhantomOP2mo ago
this is the column the sql file was missing the CREATE TYPE status AS ENUM I added that manually I'll submit a minimal reproduction tomorrow
mosess
mosess2mo ago
this is my exact dilema, any permanent fix yet? i had to create the type manually in the migration file.
Phantom
PhantomOP2mo ago
I gave up on drizzle and reverted back to prisma
mosess
mosess2mo ago
damn, sad. i can't give up now. they need to fix this.
TOSL
TOSL2mo ago
Phantom, didn't provide much to go on so helping is hard. Share your schema and maybe your config. Also share the output of drizzle generate
mosess
mosess2mo ago
so i kind of hacked my way around, i used
export * from './enums'
export * from './enums'
and all was well with the world for a while. thank you for offering to help.
Chev
Chev2mo ago
you need include the enum in your exported schema
export const status = pgEnum('status', [
'created',
'generating',
'generated',
'error',
]);

export const Widget = pgTable('widget', {
status: status().notNull().default('created'),
...
export const status = pgEnum('status', [
'created',
'generating',
'generated',
'error',
]);

export const Widget = pgTable('widget', {
status: status().notNull().default('created'),
...
TOSL
TOSL2mo ago
They claim to have already exported the pgEnum. That's the first suggestion I made.

Did you find this page helpful?