Check for empty string in postgres

Hi. First post. πŸ™‚ Started looking into migrating our project to drizzle today and am loving it so far. I want to add a not-empty check and from what I gathered from the docs and this example https://github.com/drizzle-team/drizzle-orm/blob/b003e523c637c81e2c522003db03d3d9bd98b723/drizzle-orm/type-tests/pg/tables.ts#L76 (which is the only one I could find) this code should work:
import { boolean, check, pgTable, uniqueIndex, varchar } from 'drizzle-orm/pg-core'
import { uuidPk } from './helpers'
import { sql } from 'drizzle-orm'

export const users = pgTable(
'auth_user',
{
id: uuidPk,
name: varchar('name').notNull(),
password: varchar('password').notNull(),
isAdmin: boolean('is_admin').notNull().default(false),
},
(users) => ({
nameIdx: uniqueIndex('auth_user_name_idx').on(users.name),
notEmptyName: check('notEmptyName', sql`${users.name} <> ''`),
})
)
import { boolean, check, pgTable, uniqueIndex, varchar } from 'drizzle-orm/pg-core'
import { uuidPk } from './helpers'
import { sql } from 'drizzle-orm'

export const users = pgTable(
'auth_user',
{
id: uuidPk,
name: varchar('name').notNull(),
password: varchar('password').notNull(),
isAdmin: boolean('is_admin').notNull().default(false),
},
(users) => ({
nameIdx: uniqueIndex('auth_user_name_idx').on(users.name),
notEmptyName: check('notEmptyName', sql`${users.name} <> ''`),
})
)
But it doesn't :/ the index works, but the check does not. There is no SQL generated for the migration but to be sure I also tested it in runtime after migrating but no luck. Any advice?
B
bloberenoberβ€’355d ago
@Andrii Sherman
AS
Andrii Shermanβ€’355d ago
@bloberenober
B
bloberenoberβ€’355d ago
this seems like a migration generation bug?
AS
Andrii Shermanβ€’355d ago
@Martnart the case is that checks are not supported in drizzle-kit yet But it’s in our backlog. You can check #drizzle-plans for that Current workaround to add check statement manually to sql file before applying to database
M
Martnartβ€’355d ago
Thanks for prompt reply. I was a bit confused because it is already being used in the test file linked above. Anyway, great job that you guys are doing. Looking forward to a bright future with drizzle πŸ™‚
Want results from more Discord servers?
Add your server
More Posts
How do I set a column to be unique in drizzle syntax for mySQL?Would something like this be correct? ```js export const authUsers = mysqlTable( 'auth_users',How to use JSON field in queryI've already made an issue on GitHub kind of pertaining to this issue, but I don't know if its actuaMySQL, PG proxy driver@Andrii Sherman Hi, Andrew! I noticed that the April milestone for drizzle-orm includes MySQL and PHow to create tables?So my understanding is that running a "migration" means creating the table with the schema in your donUpdateNow usageis onUpdateNow simlar to prisma's @updatedAt ? I.e., updated_at col is auto-updated. If so, is thereERR_PACKAGE_PATH_NOT_EXPORTED on 0.25.1Just updated for the new ESM support, and noticed I can no longer generate migrations (See image) IUPSERT many ?I have a table called `crmCompanies` containing companies from my client's CRMs. Each day, I recemissing type declarations in mysql-core imports (>v0.25.1)after upgrading drizzle-orm to v0.25.1 i get some errors in my schema telling me that `drizzle-orm/mdrizzle-orm@0.25.0 broke edge supportSeems like the ESM Support broke some stuff in the edge runtime land. This my vercel build output wiDoes Drizzle support type CUID?In Prisma i can use: id String @id @default(cuid()) Do we have similar solutions?Get column name in error messagesIs there a way to get column names exactly where the query is failing, for example when the FOREIGN Using Drizzle as a package in Turborepo doesn't work ?I have a monorepo (Turborepo) with a shared package called @mono/database in which I put my drizzle Argument of type 'Database' is not assignable to parameter of type 'D1Database'.I'm trying to use drizzle with cloudflare d1 but getting this error. Any help?drizzle-zod update schema?is there any plan for `createUpdateSchema` from `drizzle-zod`?