executing an `update` statement does not use `.onUpdateNow()` defined in schema

FF0rce5/19/2023
Hello everyone 🙂 I have the following schema for my USERS table:
export const users = mysqlTable("USERS", {
id: varchar("ID", { length: 21 }).notNull().primaryKey(),
hostname: varchar("HOSTNAME", { length: 253 }).notNull(),
email: varchar("EMAIL", { length: 320 }).notNull(),
verified: boolean("VERIFIED").notNull().default(false),
createdAt: timestamp("CREATED_AT").notNull().defaultNow(),
updatedAt: timestamp("UPDATED_AT").onUpdateNow(),
});
export const users = mysqlTable("USERS", {
id: varchar("ID", { length: 21 }).notNull().primaryKey(),
hostname: varchar("HOSTNAME", { length: 253 }).notNull(),
email: varchar("EMAIL", { length: 320 }).notNull(),
verified: boolean("VERIFIED").notNull().default(false),
createdAt: timestamp("CREATED_AT").notNull().defaultNow(),
updatedAt: timestamp("UPDATED_AT").onUpdateNow(),
});
As I understand correctly, as soon as I use db.update(users)... the updatedAt should be automatically be set to new Data:
await db
.update(users)
.set({
...(putUser.email ? { email: putUser.email } : {}),
...(putUser.url ? { hostname: new URL(putUser.url).hostname } : {}),
})
.where(eq(users.id, user.id));
await db
.update(users)
.set({
...(putUser.email ? { email: putUser.email } : {}),
...(putUser.url ? { hostname: new URL(putUser.url).hostname } : {}),
})
.where(eq(users.id, user.id));
The email and hostname values are updated accordingly but the updatedAt column does not seem to be touched. Am I missunderstanding something here ? Thanks in advance, David
ASAndrii Sherman5/19/2023
Do you have on update now() in your database directly?
FF0rce5/19/2023
I am using planetscale and as far as I know they dont support it so basically I just have to update it by myself
ASAndrii Sherman5/19/2023
yes, if database has no support for it - it won't work currently in drizzle. Because everything defined in schema is full representation for database default/functions/constraints/etc.
FF0rce5/19/2023
ahhh good to know thanks a lot

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Help with raw queryThe following query is all raw. Is there a way to make SQL raw only the part of the `where` clause? Create GIN index in PostgresI need to create this index in postgres: ```sql CREATE INDEX users_name_gin_trgm_idx ON users USINGHow to plus 1 to the current value of a column when updateHow to plus 1 to the current value of a column when updating a recordOrdering by a string column but coercing it to a number for orderingI have a column that mostly contains numbers with only a very few exceptions and want to apply ordertype union on entire rowi can think of workarounds for this but figured i'd ask if i have a table that's like [id, type, daProper query results inferencePosting my GitHub discussion here for more visibility: https://github.com/drizzle-team/drizzle-orm/dDrizzle with Next 13.4.2 & Vercel Postgres TimeoutHi all. I'm trying out NextJS server actions and Drizzle for the first time. I have it hooked up tI think I don't really understand migrations local sqlite.It's a local sqlite db (`DB_URL=file:dev.db`) in a nextjs & trpc setup. I'm trying drizzle for the fConnecting to Vercel PostgresI'm trying to connect to Vercel Postgres like this: ```ts import { drizzle } from "drizzle-orm/verceinsertID not returned correctly when using custom UUID```export const users = mysqlTable("users", { id: varchar("id", { length: 36 }) .primaryKey() weird ilike postgres behaviorhi, I have a very weird issue when trying to filter using ilike in postgres, both my local instance Cannot make a .all() query on an empty table (Bun SQLITE)I am new to SQLITE but i'm unable to make a .all() query on an empty table in a Bun with Drizzle proSelf referencing nullable ID field not assigneable in a `eq` statementI am not sure if I encountered another edge case but basically I have a self-referencing table whereCustom `Select` object returns type `any`Databases like Planetscale do not support FK constraints. As I understand I can manipulate the retur