fix: retain import actor attribution

Persist record and actor identities through job completion.\nWrite one bounded transactional completion audit per job.
This commit is contained in:
Marc-André Bombeck committed 2026-08-06 02:00:35 +02:00
1 parent adb932052c
commit 620817b10b
19 files changed
+211 -63

No files matched your search

+10 -2
View File
@@ -49,16 +49,24 @@ export async function auditLog(
action: string,
opts: {
userId?: string | null;
/** Explicit worker attribution when no request context remains. */
actorUserId?: string | null;
/** Use the active transaction when the audit must commit atomically. */
client?: Pick<typeof prisma, "auditLog">;
details?: Record<string, unknown>;
ipAddress?: string | null;
} = {},
) {
const userId = opts.userId ?? null;
const entry = await prisma.auditLog.create({
const client = opts.client ?? prisma;
const entry = await client.auditLog.create({
data: {
action,
userId,
actorUserId: actingActorFor(userId),
actorUserId:
opts.actorUserId === undefined
? actingActorFor(userId)
: opts.actorUserId,
details: opts.details ? JSON.stringify(opts.details) : null,
ipAddress: opts.ipAddress ?? null,
},