fix(backend): set updatedAt explicitly in all mutations

onConflictDoUpdate bypasses Drizzle's $onUpdate hook.
Set updatedAt explicitly in all mutation methods.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-16 01:24:24 +00:00
parent b813f27f0a
commit 21f78f7721

View File

@@ -30,7 +30,7 @@ export function sources(db: Database, userId: string) {
async enableSource(sourceId: string) {
const rows = await db
.update(userSources)
.set({ enabled: true })
.set({ enabled: true, updatedAt: new Date() })
.where(and(eq(userSources.userId, userId), eq(userSources.sourceId, sourceId)))
.returning({ id: userSources.id })
@@ -43,7 +43,7 @@ export function sources(db: Database, userId: string) {
async disableSource(sourceId: string) {
const rows = await db
.update(userSources)
.set({ enabled: false })
.set({ enabled: false, updatedAt: new Date() })
.where(and(eq(userSources.userId, userId), eq(userSources.sourceId, sourceId)))
.returning({ id: userSources.id })
@@ -59,7 +59,7 @@ export function sources(db: Database, userId: string) {
.values({ userId, sourceId, config })
.onConflictDoUpdate({
target: [userSources.userId, userSources.sourceId],
set: { config },
set: { config, updatedAt: new Date() },
})
},
@@ -67,7 +67,7 @@ export function sources(db: Database, userId: string) {
async updateCredentials(sourceId: string, credentials: Buffer) {
const rows = await db
.update(userSources)
.set({ credentials })
.set({ credentials, updatedAt: new Date() })
.where(and(eq(userSources.userId, userId), eq(userSources.sourceId, sourceId)))
.returning({ id: userSources.id })