Skip to content

Conversation

@Balance8
Copy link

@Balance8 Balance8 commented Sep 15, 2025

🚀 Feature: Support for Drizzle's new $onUpdate functionality

This PR adds support for Drizzle ORM v0.30.5's new $onUpdate functionality by mapping Prisma's @updatedAt attribute to Drizzle's $onUpdate(() => new Date()).

📋 Changes

  • PostgreSQL Generator: Maps @updatedAt to .$onUpdate(() => new Date())
  • MySQL Generator: Maps @updatedAt to .$onUpdate(() => new Date())
  • SQLite Generator: Maps @updatedAt to .$onUpdate(() => new Date())

🎯 Implementation Details

  • Follows established codebase patterns for field modifier handling
  • Consistent implementation across all three database generators
  • Uses Prisma's native field.isUpdatedAt DMMF property
  • Zero breaking changes to existing functionality
  • Minimal code changes (3 lines per generator)

📖 Usage

Prisma Schema:

model User {
  id        Int      @id @default(autoincrement())
  name      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt  // This will now use $onUpdate
}

Generated Drizzle Schema:

export const User = pgTable('User', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  createdAt: timestamp('createdAt', { precision: 3 }).notNull().defaultNow(),
  updatedAt: timestamp('updatedAt', { precision: 3 }).notNull().$onUpdate(() => new Date())
});

🔗 Related

✅ Testing

  • All existing tests pass
  • Build completes successfully
  • Follows TypeScript strict mode requirements

This enhancement provides seamless integration between Prisma's @updatedAt attribute and Drizzle's new $onUpdate functionality, enabling automatic timestamp updates when records are modified.

- Map Prisma's @updatedat attribute to Drizzle's new $onUpdate(() => new Date())
- Consistent implementation across PostgreSQL, MySQL, and SQLite generators
- Follows established codebase patterns for field modifier handling
- Supports Drizzle ORM v0.30.5+ $onUpdate feature for automatic timestamp updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant