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
bloberenober
bloberenober16mo ago
Looks correct @Andrii Sherman
Andrii Sherman
Andrii Sherman16mo ago
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 ⚡16mo ago
Haha sorry to be a deep source code reader 😂
bloberenober
bloberenober16mo ago
you found an easter egg 🥚