import { PrismaService } from '../src/prisma/prisma.service'; /** * Schema-level guarantees of the platform backbone migration that the Prisma * schema alone cannot express (UNLOGGED table, nullable unique dedupe key). */ describe('Platform backbone schema (e2e)', () => { let prisma: PrismaService; const suffix = `${Date.now()}-${Math.round(Math.random() * 1e6)}`; beforeAll(() => { prisma = new PrismaService(); }); afterAll(async () => { await prisma.domainEvent.deleteMany({ where: { aggregateId: `t-${suffix}` }, }); await prisma.$disconnect(); }); it('creates ThrottlerHit as an UNLOGGED table', async () => { const [row] = await prisma.$queryRaw< { relpersistence: string }[] >`SELECT relpersistence::text AS relpersistence FROM pg_class WHERE relname = 'ThrottlerHit'`; expect(row.relpersistence).toBe('u'); }); it('keeps at most one event per dedupe key', async () => { const data = { type: 'TaskDue', aggregateType: 'Task', aggregateId: `t-${suffix}`, payload: {}, correlationId: 'c', dedupeKey: `TaskDue:t-${suffix}:2026-10-13`, }; expect( ( await prisma.domainEvent.createMany({ data: [data], skipDuplicates: true, }) ).count, ).toBe(1); expect( ( await prisma.domainEvent.createMany({ data: [data], skipDuplicates: true, }) ).count, ).toBe(0); }); });