praiz_dqoder
DTDrizzle Team
•Created by praiz_dqoder on 3/4/2024 in #help
I need help with Enums in Drizzle.
still throws error
export const roleEnum = pgEnum('role', ['user', 'admin', 'superAdmin']);
so i renamed userRole to roleEnum and here is the table....
export const users = pgTable(
'users',
{
id: serial('id').primaryKey().notNull(),
name: varchar('name', { length: 70 }).notNull(),
email: varchar('email', { length: 70 }).unique().notNull(),
password: varchar('password', { length: 20 }).notNull(),
role: roleEnum('role').default('user'),
refreshToken: varchar('refresh_token').default(null),
createdAt: timestamp('created_at', {
precision: 6,
withTimezone: true,
}).defaultNow(),
updatedAt: timestamp('updated_at', {
precision: 6,
withTimezone: true,
}).defaultNow(),
},
(users) => {
return {
nameIdx: index('name_idx').on(users.name),
emailIdx: index('email_idx').on(users.email),
};
},
);
//here is the generated migrations
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(70) NOT NULL,
"email" varchar(70) NOT NULL,
"password" varchar(20) NOT NULL,
"role" "role" DEFAULT 'user',
"refresh_token" varchar DEFAULT null,
"created_at" timestamp (6) with time zone DEFAULT now(),
"updated_at" timestamp (6) with time zone DEFAULT now(),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
role still doesnt pass as Enum as stated when writing traditional postgres enums.
4 replies