Files
iios/packages/iios-service/src/test-utils/reset-db.ts
T

20 lines
991 B
TypeScript

import type { PrismaClient } from '@prisma/client';
/**
* FK-safe full reset for DB-backed specs. TRUNCATE … CASCADE clears every kernel
* table regardless of relation order, so specs don't each need to know the full
* delete order (which broke once Inbox added FK references to interaction/thread/actor).
*/
export async function resetDb(prisma: PrismaClient): Promise<void> {
await prisma.$executeRawUnsafe(
`TRUNCATE TABLE
"IiosInboundRawEvent","IiosDeliveryAttempt","IiosOutboundCommand","IiosRateLimitBucket",
"IiosTicketStateHistory","IiosTicketThreadLink","IiosCallbackRequest","IiosTicket",
"IiosSupportTeamMember","IiosSupportQueue",
"IiosInboxItemStateHistory","IiosInboxItem","IiosUnreadCounter","IiosMessageReceipt",
"IiosOutboxEvent","IiosProcessedEvent","IiosMessagePart","IiosInteraction",
"IiosThreadParticipant","IiosThread","IiosActorRef","IiosSourceHandle","IiosChannel","IiosScope"
RESTART IDENTITY CASCADE`,
);
}