Check

Hello there, from this discussion: https://discord.com/channels/1043890932593987624/1090486363251544124/1093092996200796200 Is it the way to add check constraint?
const companySize = ["tpe", "pme", "eti", "ge"] as const;

export const Company = pgTable(
"company",
{
id: uuid("id").defaultRandom().primaryKey(),
companySize: text("company_size", { enum: [...companySize] }).notNull()
},
(Company) => ({
onlyTheseSize: check(
"only_these_size",
sql`${Company.companySize} in(${companySize.join(",")})`
),
})
);
const companySize = ["tpe", "pme", "eti", "ge"] as const;

export const Company = pgTable(
"company",
{
id: uuid("id").defaultRandom().primaryKey(),
companySize: text("company_size", { enum: [...companySize] }).notNull()
},
(Company) => ({
onlyTheseSize: check(
"only_these_size",
sql`${Company.companySize} in(${companySize.join(",")})`
),
})
);
It produces nothing in the generated migration 🧐 drizzle-kit: v0.17.4 drizzle-orm: v0.23.5
4 Replies
Dan
Dan2y ago
Looks correct @Andrii Sherman
Andrii Sherman
Yeah, drizzle kit is not aware of any checks yet But we will add support for it Have in backlog Workaround to write them manually Same as you did with unique constraints
rphlmr ⚡
rphlmr ⚡OP2y ago
Haha sorry to be a deep source code reader 😂
Dan
Dan2y ago
you found an easter egg 🥚
Want results from more Discord servers?
Add your server