-
-
Notifications
You must be signed in to change notification settings - Fork 688
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]: enum as array, not possible? #1564
Comments
so im not alone |
since you are using an array you cannot have the literal as default you need to do it like this export const userRoles = pgEnum("user_role", ["admin", "member"]);
export const user = pgTable("user", {
id: uuid("id").notNull().defaultRandom().primaryKey(),
roles: userRoles("roles").array().notNull().default(sql`'{"member"}'`),
}); |
The sql generated by Drizzle probably looks something like this ALTER TABLE "users" ADD COLUMN "roles" userRoles[] while it should be looking like ALTER TABLE "users" ADD COLUMN "roles" "userRoles"[] I cannot figure out where Drizzle actually loads the sql from but modifying |
Any resolution on this? |
❌ Does not work: ✅ Works |
Still an issue.. :/ |
Should be fixed in |
Hi @AndriiSherman, unfurtonuately, this issue is still not resolved by export const myEnum = pgEnum('my_enum', [
'VALUE1',
'VALUE2'
])
export const myTable = pgTable('my_table', {
id: bigserial('id', { mode: 'bigint' }).primaryKey(),
enum: myEnum('enum').array().notNull(), // <-- does not work
})
export const myTableWithDefault = pgTable('my_table_with_default', {
id: bigserial('id', { mode: 'bigint' }).primaryKey(),
enum: myEnum('enum').array().default([]).notNull(), // <-- does not work with default value either
}) Running Maybe someone else could confirm this behavior. My local ESM setup uses workarounds mentioned here. However, I checked the correct |
You can work around this by using lowercase enum names. The test cases for this use snake case, which works fine. If your enum is named using camel case (or any uppercase characters) it will trigger this bug, as @onursagir suggested here: Postgres folds unquoted names to lowercase, so if your enum is named
I think the problem is here: As far as I can tell (I've only had a quick look) quoting the enum name in return `"${this.baseColumn.getSQLType()}"[${typeof this.size === 'number' ? this.size : ''}]`; |
I tried muscleTargets: muscleTargetEnum("muscle_targets")
.array()
.$type<MuscleTarget[]>()
.default([])
.notNull(), tested with postgres and works. |
This is still broken for PascalCase enums
|
this still doesn't work for me on 0.24.2. I get: |
The way I worked around this is I just created the enum at the top of the migration file. |
What version of
drizzle-orm
are you using?0.29.0
What version of
drizzle-kit
are you using?0.20.4
Describe the Bug
a simple example:
when i try to migrate this, i got the error:
is it not implemented or is this a bug...?
thx.
Expected behavior
No response
Environment & setup
No response
The text was updated successfully, but these errors were encountered: