Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]:(0 , import_pg_core.enum) is not a function #3825

Open
1 task done
DavidHombe96 opened this issue Dec 23, 2024 · 1 comment
Open
1 task done

[BUG]:(0 , import_pg_core.enum) is not a function #3825

DavidHombe96 opened this issue Dec 23, 2024 · 1 comment
Labels
bug Something isn't working priority Will be worked on next

Comments

@DavidHombe96
Copy link

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.38.2

What version of drizzle-kit are you using?

0.30.1

Other packages

No response

Describe the Bug

1-Does not generate tables
2-just create a user schema and add an enum role that can be user or admin and run npx drizzle-kit generate
import { pgTable, serial, varchar, text, timestamp, pgEnum } from "drizzle-orm/pg-core";
const roleEnum = pgEnum("roles", ["client", "profissional"])

export const users = pgTable(
"users", // Nome da tabela
{
id: serial("id").primaryKey(),
name: varchar("name", { length: 100 }).notNull(),
email: varchar("email", { length: 100 }).notNull().unique(),
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
phone: varchar("phone", { length: 15 }),
address: text("address"),
userType: roleEnum("roles").notNull(),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.$onUpdateFn(() => new Date()),
}
);

3- user table created
4- Postgres
5-It only happens when I work with node and express, in nextjs it works fine, (pg and neon )
6- I'm not using monorepo
7- I'm using javascript
8- using node

@DavidHombe96 DavidHombe96 added the bug Something isn't working label Dec 23, 2024
@L-Mario564 L-Mario564 added the priority Will be worked on next label Dec 23, 2024
@AdamAkiva
Copy link

TLDR
If I understood the issue correctly you need to export the enum as well, e.g:

export const roleEnum = pgEnum("roles", ["client", "profissional"])

Longer explanation:
I'm not sure I'm understanding you correctly.
When I copy the code you've provided the table is generated but without the enum resulting in error when running the actual migration on the database. (On postgres it is code: 42704 which means UNDEFINED OBJECT which refers to the line "roles" "roles" NOT NULL in the generated sql),
I've assumed this is the issue you have, and in order to make the enum "work", you have to export it from your schema as well:

export const roleEnum = pgEnum("roles", ["client", "profissional"])

After adding the export the generated SQL looks like:

CREATE TYPE "public"."roles" AS ENUM('client', 'profissional');--> statement-breakpoint
CREATE TABLE "users" (
	"id" serial PRIMARY KEY NOT NULL,
	"name" varchar(100) NOT NULL,
	"email" varchar(100) NOT NULL,
	"password_hash" varchar(255) NOT NULL,
	"phone" varchar(15),
	"address" text,
	"roles" "roles" NOT NULL,
	"created_at" timestamp with time zone DEFAULT now(),
	"updated_at" timestamp with time zone DEFAULT now(),
	CONSTRAINT "bla_email_unique" UNIQUE("email")
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Will be worked on next
Projects
None yet
Development

No branches or pull requests

3 participants