© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
CrazyCroatKid

Right way to make UpdatedAt column in Drizzle?

I'm trying to copy the way prisma was able to create a column that would update to the newest time when a row is changed. Is this a good implementation below or have people had issues with this that have tried to implement it?
export const users = pgTable("users", {
  id: text("id")
    .$defaultFn(() => createId())
    .primaryKey()
    .notNull(),
  kindeUserId: text("kinde_user_id").unique(),
  email: text("email").unique(),
  firstName: text("first_name"),
  lastName: text("last_name"),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at") // <-- HERE
    .notNull()
    .default(sql`(CURRENT_TIMESTAMP)`)
    .$onUpdate(() => sql`(CURRENT_TIMESTAMP)`),
});
export const users = pgTable("users", {
  id: text("id")
    .$defaultFn(() => createId())
    .primaryKey()
    .notNull(),
  kindeUserId: text("kinde_user_id").unique(),
  email: text("email").unique(),
  firstName: text("first_name"),
  lastName: text("last_name"),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at") // <-- HERE
    .notNull()
    .default(sql`(CURRENT_TIMESTAMP)`)
    .$onUpdate(() => sql`(CURRENT_TIMESTAMP)`),
});

A reference example the way Prisma had it
model User {
  id        Int      @id @default(autoincrement())
  name      String?
  email     String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt // <-- HERE
}
model User {
  id        Int      @id @default(autoincrement())
  name      String?
  email     String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt // <-- HERE
}
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

UpdatedAt column - Postgres
Drizzle TeamDTDrizzle Team / help
3y ago
How to Reference a Column Type in Drizzle
Drizzle TeamDTDrizzle Team / help
2y ago
Drizzle rename id column
Drizzle TeamDTDrizzle Team / help
3y ago
Column name different in drizzle magic sql vs drizzle-orm
Drizzle TeamDTDrizzle Team / help
2y ago