pgEnum + Neon migrations type error

Please someone help me, I don't understand why I'm getting this error on migrations:
NeonDbError: type "roles" does not exist
at execute (D:\PROJECT\node_modules\.pnpm\@[email protected]\node_modules\@neondatabase\serverless\index.js:1555:56)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async migrate (D:\PROJECT\node_modules\.pnpm\d[email protected]_@[email protected]_@[email protected]_@[email protected]_@xat_xasefqyfafq3r2cbdr2fxaigre\node_modules\src\neon-http\migrator.ts:47:5)
at async main (D:\PROJECT\src\db\migrate.ts:14:5) {
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: '203',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType',
sourceError: undefined
}
NeonDbError: type "roles" does not exist
at execute (D:\PROJECT\node_modules\.pnpm\@[email protected]\node_modules\@neondatabase\serverless\index.js:1555:56)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async migrate (D:\PROJECT\node_modules\.pnpm\d[email protected]_@[email protected]_@[email protected]_@[email protected]_@xat_xasefqyfafq3r2cbdr2fxaigre\node_modules\src\neon-http\migrator.ts:47:5)
at async main (D:\PROJECT\src\db\migrate.ts:14:5) {
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: '203',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType',
sourceError: undefined
}
This is my user schema:
import { createId } from "@paralleldrive/cuid2";
import {
AnyPgColumn,
boolean,
pgEnum,
pgTable,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";

export const RoleEnum = pgEnum("roles", ["user", "admin"]);

export const users = pgTable(
"user",
{
id: text("id")
.notNull()
.primaryKey()
.$defaultFn(() => createId()),

name: varchar("name", { length: 320 }),

email: varchar("email", { length: 320 }).notNull().unique(),
password: varchar("password", { length: 255 }),

emailVerified: timestamp("emailVerified", { mode: "date" }),

image: text("image"),

role: RoleEnum("roles").default("user"),

twoFactorEnabled: boolean("twoFactorEnabled").default(false),

customerID: text("customerID"),

createdAt: timestamp("created_at").defaultNow(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
})
import { createId } from "@paralleldrive/cuid2";
import {
AnyPgColumn,
boolean,
pgEnum,
pgTable,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";

export const RoleEnum = pgEnum("roles", ["user", "admin"]);

export const users = pgTable(
"user",
{
id: text("id")
.notNull()
.primaryKey()
.$defaultFn(() => createId()),

name: varchar("name", { length: 320 }),

email: varchar("email", { length: 320 }).notNull().unique(),
password: varchar("password", { length: 255 }),

emailVerified: timestamp("emailVerified", { mode: "date" }),

image: text("image"),

role: RoleEnum("roles").default("user"),

twoFactorEnabled: boolean("twoFactorEnabled").default(false),

customerID: text("customerID"),

createdAt: timestamp("created_at").defaultNow(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
})
3 Replies
DoggeSlapper
DoggeSlapper3mo ago
You referencing roles somewhere before it exists Is this the only table u have?
DragonCoder99
DragonCoder99OP3mo ago
Yep I didn't put it in my app yet I was just trying to setup the roles in my table I double checked and the only references to roles is in this file There is a 2nd table accounts It follows the Auth.js setup but just got account and users
DoggeSlapper
DoggeSlapper3mo ago
This is not working properly I can confirm it @DragonCoder99 the issue on my case was not exporting the enum if u exporting it should be working on latest I just tested
Want results from more Discord servers?
Add your server