Misho Shubitidze
Misho Shubitidze
DTDrizzle Team
Created by Misho Shubitidze on 1/10/2025 in #help
conditional columns
is there a better way of doing this? if the userType column equals to 'artist', the nickname column should be notNull(), but in case of 'customer' it should be null also, the firstName, lastName and the city columns should be filled out before isSetupComplete column can be set to true below is what i came up with open to tips and suggestions, thanks in advance!
export const users = pgTable('users', {
id: uuid().notNull().primaryKey().defaultRandom(),
email: text().notNull().unique(),
password: text().notNull(),
code: text().notNull(),
isVerified: boolean().notNull().default(false),
type: pgEnum('user_type', ['customer', 'artist'])(),
firstName: text(),
lastName: text(),
city: text(),
nickname: text(),
isSetupComplete: boolean().generatedAlwaysAs(
(): SQL => sql`CASE
WHEN ${users.isVerified} = true
AND ${users.firstName} IS NOT NULL
AND ${users.lastName} IS NOT NULL
AND ${users.city} IS NOT NULL
AND ${users.type} IS NOT NULL
AND (
${users.type} = 'customer'
OR (${users.type} = 'artist' AND ${users.nickname} IS NOT NULL)
)
THEN true
ELSE false
END`,
),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
});
export const users = pgTable('users', {
id: uuid().notNull().primaryKey().defaultRandom(),
email: text().notNull().unique(),
password: text().notNull(),
code: text().notNull(),
isVerified: boolean().notNull().default(false),
type: pgEnum('user_type', ['customer', 'artist'])(),
firstName: text(),
lastName: text(),
city: text(),
nickname: text(),
isSetupComplete: boolean().generatedAlwaysAs(
(): SQL => sql`CASE
WHEN ${users.isVerified} = true
AND ${users.firstName} IS NOT NULL
AND ${users.lastName} IS NOT NULL
AND ${users.city} IS NOT NULL
AND ${users.type} IS NOT NULL
AND (
${users.type} = 'customer'
OR (${users.type} = 'artist' AND ${users.nickname} IS NOT NULL)
)
THEN true
ELSE false
END`,
),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
});
1 replies
DTDrizzle Team
Created by Misho Shubitidze on 4/16/2024 in #help
adding a new table column with default value drops all table data without warning
No description
2 replies
DTDrizzle Team
Created by Misho Shubitidze on 2/29/2024 in #help
ilike substitute for mysql
No description
2 replies
DTDrizzle Team
Created by Misho Shubitidze on 6/29/2023 in #help
added drizzle-zod to my project and I am getting this error when starting the dev server - error ./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/drizzle-zod/index.mjs Attempted import error: 'is' is not exported from 'drizzle-orm' (imported as 'n'). Import trace for requested module: ./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/drizzle-zod/index.mjs ./drizzle/schema.ts ./app/page.tsx am i doing something wrong?
4 replies