targo-backend/test/utils/reset-db.ts

22 lines
894 B
TypeScript

import { INestApplication } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
// export async function resetDb(app: INestApplication) {
// const prisma = app.get(PrismaService);
// const KEEP_USERS = process.env.E2E_KEEP_USERS === '1';
// const excludes = ['_prisma_migrations', ...(KEEP_USERS ? ['users'] : [])];
// const notIn = excludes.map(n => `'${n}'`).join(', ');
// const rows = await prisma.$queryRawUnsafe<Array<{ tablename: string }>>(`
// SELECT table_name AS tablename
// FROM information_schema.tables
// WHERE table_schema = 'public'
// AND table_type = 'BASE TABLE'
// AND table_name NOT IN (${notIn})
// `);
// if (!rows.length) return;
// const list = rows.map(r => `"public"."${r.tablename}"`).join(', ');
// await prisma.$executeRawUnsafe(`TRUNCATE TABLE ${list} RESTART IDENTITY CASCADE;`);
// }