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]: introspect:pg column not using generated enum name #1648

Closed
cosileone opened this issue Dec 14, 2023 · 4 comments
Closed

[BUG]: introspect:pg column not using generated enum name #1648

cosileone opened this issue Dec 14, 2023 · 4 comments
Labels
bug Something isn't working drizzle/kit

Comments

@cosileone
Copy link

What version of drizzle-orm are you using?

0.29.1

What version of drizzle-kit are you using?

0.20.6

Describe the Bug

running drizzle-kit introspect:pg on my pg database generates schema file but with incorrect column type.

export const timeLeft = pgEnum("TimeLeft", ['VERY_LONG', 'SHORT', 'MEDIUM', 'LONG'])

export const auction = pgTable("Auction", {
	id: serial("id").primaryKey().notNull(),
	bid: integer("bid").notNull(),
	buyout: integer("buyout").notNull(),
	quantity: integer("quantity").notNull(),

	timeLeft: time("timeLeft").notNull(), // <------- NOTICE usage of nonexistent "time" definition, I think it should be "timeLeft"?

	itemId: integer("itemId").notNull().references(() => item.id, { onDelete: "cascade", onUpdate: "cascade" } ),
	createdAt: timestamp("createdAt", { precision: 3, mode: 'string' }).defaultNow().notNull(),
	updatedAt: timestamp("updatedAt", { precision: 3, mode: 'string' }).notNull(),
},
(table) => {
	return {  /* ... */ }
});

Expected behavior

export const timeLeft = pgEnum("TimeLeft", ['VERY_LONG', 'SHORT', 'MEDIUM', 'LONG'])

export const auction = pgTable("Auction", {
	id: serial("id").primaryKey().notNull(),
	bid: integer("bid").notNull(),
	buyout: integer("buyout").notNull(),
	quantity: integer("quantity").notNull(),

	timeLeft: timeLeft("timeLeft").notNull(), // <------- correct type now

	itemId: integer("itemId").notNull().references(() => item.id, { onDelete: "cascade", onUpdate: "cascade" } ),
	createdAt: timestamp("createdAt", { precision: 3, mode: 'string' }).defaultNow().notNull(),
	updatedAt: timestamp("updatedAt", { precision: 3, mode: 'string' }).notNull(),
},
(table) => {
	return {  /* ... */ }
});

Environment & setup

macos, node 18.18.2, typescript 5.3.2, AWS RDS PostgresQL micro.t3 instance

@cosileone cosileone added the bug Something isn't working label Dec 14, 2023
@Angelelz
Copy link
Collaborator

What is timeLeft type?
The introspect command just used the pg time data type. I don't think there is a timeLeft data time in postgres

@cosileone
Copy link
Author

cosileone commented Dec 14, 2023

What is timeLeft type? The introspect command just used the pg time data type. I don't think there is a timeLeft data time in postgres

Ah you will notice timeLeft is an enum defined on the very first line of the code snippet above! Generated from an enum defined on my database called TimeLeft. It's values are ['VERY_LONG', 'SHORT', 'MEDIUM', 'LONG']

The problem is that introspect is generating the enum, but not connecting it to the column that is using it

@nikhiljay
Copy link

Any update on this? Running into the same issue where a couple enums are being introspected as time instead

@AndriiSherman
Copy link
Member

This should be fixed in drizzle-kit@0.24.1
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