How to make a nullable field from table schema be notNull using drizzle-zod?

In this case, I want to make the last_name a required field in the updateProfileSchema.

export const profile = mysqlTable("profile", {
  first_name: varchar("first_name").notNull(),
  last_name: varchar("last_name")
})

const updateProfileSchema = createInsertSchema(profile, {
  last_name: schema => schema.last_name.min(1)
  // last_name: z.string().min(1) <-- THIS DONT WORK EITHER
}).required({
  last_name: true
})

type UpdateProfile = z.infer<typeof updateProfileSchema>
// type UpdateProfile = {
//   first_name: string
//   last_name: string | null <-- HOW TO REMOVE NULL FROM HERE???????????
// }
Was this page helpful?