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]: Incorrect Schema Generated when introspecting extisting pg database #1985

Closed
sirjager opened this issue Mar 8, 2024 · 2 comments
Closed
Labels
bug Something isn't working drizzle/kit

Comments

@sirjager
Copy link

sirjager commented Mar 8, 2024

What version of drizzle-orm are you using?

0.30.0

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

Context

I am using neon's PostgreSQL db, which is connected to my Directus instance.
I want to query directly from db using drizzle, so that i don't have to deploy Directus,
Currently i am running Directus locally on docker with neon db.

What i have done

  1. Generated schema from existing db using drizzle-kit introspect:pg

Error

In the generated schema and SQL file

Default value is causing error

--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "directus_roles" (
	"id" uuid PRIMARY KEY NOT NULL,
	"name" varchar(100) NOT NULL,
	"icon" varchar(30) DEFAULT 'supervised_user_circle'::character varying NOT NULL,
	"description" text,
	"ip_access" text,
	"enforce_tfa" boolean DEFAULT false NOT NULL,
	"admin_access" boolean DEFAULT false NOT NULL,
	"app_access" boolean DEFAULT true NOT NULL
);

Parsing error: ',' expected. 22:71:70 eslint_d
',' expected. 22:72:70 typescript1005

export const directusRoles = pgTable("directus_roles", {
	id: uuid("id").primaryKey().notNull(),
	name: varchar("name", { length: 100 }).notNull(),
	icon: varchar("icon", { length: 30 }).default('supervised_user_circle'::character varying).notNull(),
	description: text("description"),
	ipAccess: text("ip_access"),
	enforceTfa: boolean("enforce_tfa").default(false).notNull(),
	adminAccess: boolean("admin_access").default(false).notNull(),
	appAccess: boolean("app_access").default(true).notNull(),
});

I have around 50 tables now, and schema will be changing as the app grows
and this issue is almost in every table.
And Every time i generate schema it generates wrong code.

Expected behavior

No response

Environment & setup

linux 6.7.8.arch1-1
Hyprland
EndeavourOS

@sirjager sirjager added the bug Something isn't working label Mar 8, 2024
@raikusy
Copy link

raikusy commented May 24, 2024

I am facing same issue. Is the any fix?

I am using drizzle-kit introspect command.
drizzle-orm v0.30.10
drizzle-kit v0.21.4

Currently I am having to search and remove all ::character varying manually from schema.ts file.

@AndriiSherman
Copy link
Member

This should be fixed in [email protected]
If you still encounter this issue, please reopen the ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/kit
Projects
None yet
Development

No branches or pull requests

4 participants