drizzle-orm
drizzle-orm copied to clipboard
[BUG]: Drizzkle kit generate wrong SQL for Postgres enum arrays and double precision array.
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
@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.
Can you show what the statement that got generated by the pgEnum?
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.
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 =(
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.
Also hit this, yet not with double precision array, but with a enum of strings.
I am hitting this issue with an enum of strings
pnpm drizzle-kit -v
drizzle-kit: v0.20.14
drizzle-orm: v0.29.4
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.