drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Drizzkle kit generate wrong SQL for Postgres enum arrays and double precision array.

Open Hebilicious opened this issue 1 year ago • 10 comments

What version of drizzle-orm are you using?

0.29.1

What version of drizzle-kit are you using?

0.20.7

Describe the Bug

Hello there, just finished migrating a big~ish project from prisma to drizzle (prisma.schema was 800lines) and I encountered this bug :

error: type "notificationtype[]" does not exist
 code: "42704"
error: type "double precision[]" does not exist
 code: "42704"

SQL line generated :

"disabledNotificationTypes" NotificationType[],
ALTER TABLE "VidStat" ADD COLUMN "watchHours" "double precision"[];

correct line

"disabledNotificationTypes" "NotificationType"[],
ALTER TABLE "VidStat" ADD COLUMN "watchHours" double precision[];

Manually editing the quotes in the sql file works.

I tried to generate them in isolation and got the same result :

ALTER TABLE "UserNotificationSetting" ADD COLUMN "disabledNotificationTypes" NotificationType[];--> statement-breakpoint
ALTER TABLE "UserNotificationSetting" ADD COLUMN "disabledEmailTypes" EmailTypes[];--> statement-breakpoint
ALTER TABLE "VidStat" ADD COLUMN "watchHours" "double precision"[];

For reference this is the TS code :

export const notificationType = pgEnum('NotificationType', ["foo", "bar"]);

const somethingLikeThis = {
    disabledNotificationTypes: notificationType('disabledNotificationTypes').array(),
    watchHours: doublePrecision('watchHours').array(),
}

Expected behavior

I expect the SQL to be generated correctly.

Environment & setup

node --version v20.5.0 macos

Hebilicious avatar Dec 20 '23 23:12 Hebilicious

@Angelelz Investigating this a little I think it might be because of the fact that I'm using camelCase / pascalCase and drizzle incorrectly quote things in this scenario.

Hebilicious avatar Dec 21 '23 11:12 Hebilicious

Can you show what the statement that got generated by the pgEnum?

Angelelz avatar Dec 21 '23 12:12 Angelelz

Can you show what the statement that got generated by the pgEnum?

--> statement-breakpoint
DO $$ BEGIN
 CREATE TYPE "EmailTypes" AS ENUM('WEEKLY_DIGEST', 'IMPORTANT_UPDATES', 'PROMOTIONS_DISCOUNTS_OFFERS', 'FEEDBACK_SURVEY', 'SUBSCRIPTION_UPDATES');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 CREATE TYPE "NotificationType" AS ENUM('NEW_COURSE', 'NEW_INSTRUCTOR_ANNOUNCEMENTS', 'COMMUNITY_ENGAGEMENT', 'ACHIEVEMENT_CELEBRATIONS');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;

These 2 statements.

Hebilicious avatar Dec 24 '23 12:12 Hebilicious

I also encountered this. Maybe this issue should be created in the drizzle-kit-mirror repository? It would be great if the problem was resolved soon, I really don't want to change name case everywhere =(

risen228 avatar Feb 01 '24 13:02 risen228

I also encountered this. Maybe this issue should be created in the drizzle-kit-mirror repository? It would be great if the problem was resolved soon, I really don't want to change name case everywhere =(

As a workaround you can fix the generated migration manually. Only need to be done once.

Hebilicious avatar Feb 01 '24 19:02 Hebilicious

Also hit this, yet not with double precision array, but with a enum of strings.

dalechyn avatar Feb 04 '24 22:02 dalechyn

I am hitting this issue with an enum of strings

pnpm drizzle-kit -v
drizzle-kit: v0.20.14
drizzle-orm: v0.29.4

SiNONiMiTY avatar Mar 03 '24 10:03 SiNONiMiTY

Also stumbled upon this issue with doublePrecison('columnName').array() generating the following sql "columnName" "double precision[]", In my case i can simply use real instead of doublePrecision as a workaround.

gunhaxxor avatar May 17 '24 11:05 gunhaxxor