fix(mining-admin): use outbox_id for event idempotency key

The outbox_events table uses outbox_id as the primary key column name
(mapped from id in Prisma). When Debezium captures changes, the message
contains outbox_id field, not id. This caused all events to have
undefined eventId, resulting in duplicate detection treating all events
as duplicates after the first one.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-12 21:41:54 -08:00
parent e981e622d4
commit 5e16adc1ec
1 changed files with 7 additions and 1 deletions

View File

@ -324,12 +324,18 @@ export class CdcConsumerService implements OnModuleInit, OnModuleDestroy {
// Debezium outbox 格式转换
// 原始格式:{ event_type, aggregate_type, aggregate_id, payload (JSON string), ... }
// 注意:不同服务的 outbox 表主键列名可能不同:
// - contribution-service: outbox_id (mapped from id in Prisma)
// - 其他服务可能使用: id
const payload = typeof data.payload === 'string'
? JSON.parse(data.payload)
: data.payload;
// 优先使用 outbox_idcontribution-service回退到 id
const eventId = data.outbox_id ?? data.id;
return {
id: String(data.id),
id: String(eventId),
eventType: data.event_type,
aggregateType: data.aggregate_type,
aggregateId: data.aggregate_id,