Enum array column

Hey there, anyone got an idea why doesn't this work:
typescript
// my column:
modules: productModuleEnum("productModule")
.array()
.notNull()
.default(sql`ARRAY[]::text[]`),

// my enum:
export const productModuleEnum = pgEnum("productModule", [
ProductModule.Specifications,
]);
typescript
// my column:
modules: productModuleEnum("productModule")
.array()
.notNull()
.default(sql`ARRAY[]::text[]`),

// my enum:
export const productModuleEnum = pgEnum("productModule", [
ProductModule.Specifications,
]);
the error:
PostgresError: type "productmodule[]" does not exist
but... why?
26 Replies
nehalist
nehalistOP•6mo ago
trying to push this to my db
rphlmr âš¡
rphlmr ⚡•6mo ago
👋 Hey This is because your productModuleEnum has to be part of your schema. It has to be exported with your tables
rphlmr âš¡
rphlmr ⚡•6mo ago
+ you will have an error on your default, it should be cast as
sql`ARRAY[]::productModule[]`
sql`ARRAY[]::productModule[]`
Ex: https://drizzle.run/oc2vp22i5bz5dke8y7oailgv
nehalist
nehalistOP•6mo ago
hey there, thanks. what do you mean by "has to be part of your schema"? it'S within my schema.ts file
rphlmr âš¡
rphlmr ⚡•6mo ago
Oh, sorry, wrong guess on my part 😅
nehalist
nehalistOP•6mo ago
there's also a proper productModule enum in my database
rphlmr âš¡
rphlmr ⚡•6mo ago
I can’t reproduce in the link i shared. I wonder if it is because I used an other name in my schema It is late for me but if you’re still in trouble I will retry tomorrow
nehalist
nehalistOP•6mo ago
what's very confusing is that the error productmodule is all lowercase while the enum in the db (and the schema) are camelCase
rphlmr âš¡
rphlmr ⚡•6mo ago
oh, yes it's the reason name is lowercased
nehalist
nehalistOP•6mo ago
but why?
export const productModuleEnum = pgEnum("productModule", [
ProductModule.Specifications,
]);

modules: productModuleEnum("productModule")
.array()
.notNull()
.default(sql`ARRAY[]::productModule[]`),
export const productModuleEnum = pgEnum("productModule", [
ProductModule.Specifications,
]);

modules: productModuleEnum("productModule")
.array()
.notNull()
.default(sql`ARRAY[]::productModule[]`),
there's nothing lowercased 😮
rphlmr âš¡
rphlmr ⚡•6mo ago
I guess it is because camelCase is not allowed for type name
CREATE TABLE IF NOT EXISTS "posts" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "posts_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"content" text NOT NULL,
"types" post_type[] DEFAULT ARRAY[]::post_type[] NOT NULL
);
CREATE TABLE IF NOT EXISTS "posts" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "posts_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"content" text NOT NULL,
"types" post_type[] DEFAULT ARRAY[]::post_type[] NOT NULL
);
when the new type (the enum) is used here
nehalist
nehalistOP•6mo ago
changed it to product_module - it works now. that's some weird issue
rphlmr âš¡
rphlmr ⚡•6mo ago
I think it's a bug honestly
nehalist
nehalistOP•6mo ago
feels a lot like it unfortunately I can't make out where in the code that happens, because - regarding the stack trace - it's in bin.cjs on line 81060 maybe it's an issue with pg, but maybe drizzle lowercases the input somewhere (which would be very weird)
rphlmr âš¡
rphlmr ⚡•6mo ago
would you mind just open an issue with your example? https://github.com/drizzle-team/drizzle-kit-mirror/issues?q=
nehalist
nehalistOP•6mo ago
I will make a standalone repo because I can't open source the project I'm working on. will try to do so asap thanks for your time
rphlmr âš¡
rphlmr ⚡•6mo ago
Oh you can just describe + the error (with your first ex) and link this thread Don't worry about a repro, it can easly be reproduce with Drizzle Run
nehalist
nehalistOP•6mo ago
unfortunately I'm facing a lot of weird issues with drizzle, like https://github.com/drizzle-team/drizzle-orm/issues/2418 or things like this. I get it that it's not 1.0 yet, but there's a voice in my head screaming "why not just use prisma again" pretty often 😦
rphlmr âš¡
rphlmr ⚡•6mo ago
repro: https://drizzle.run/n5dbm1kdp1bbub4ulnaqhi5w Really surprising for this I will look at your repro linked in the issue tomorrow
rphlmr âš¡
rphlmr ⚡•6mo ago
I think it is a turbo repo issue but I will look at that
nehalist
nehalistOP•6mo ago
you mean the 2418 type thing?
rphlmr âš¡
rphlmr ⚡•6mo ago
the typing error. I also wonder why it happen for the OP of this issue. Will look at your https://github.com/nehalist/drizzle-turborepo-type-error
GitHub
GitHub - nehalist/drizzle-turborepo-type-error
Contribute to nehalist/drizzle-turborepo-type-error development by creating an account on GitHub.
nehalist
nehalistOP•6mo ago
thanks a lot
rphlmr âš¡
rphlmr ⚡•6mo ago
"module": "ESNext",
"moduleResolution": "Bundler",
"module": "ESNext",
"moduleResolution": "Bundler",
should fix the issue (in your base.json or in the compilerOptions of your database package's tsconfig) https://www.totaltypescript.com/tsconfig-cheat-sheet#quickstart You can also have one tsconfig for packages. Then "module": "preserve", is enought (without moduleResolution)
rphlmr âš¡
rphlmr ⚡•6mo ago
No description
Want results from more Discord servers?
Add your server