Skip to content

Commit

Permalink
Try map
Browse files Browse the repository at this point in the history
  • Loading branch information
devneill committed Sep 28, 2024
1 parent a411a4a commit e279227
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tests/db-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ export async function cleanupDb(prisma: PrismaClient) {
await prisma.$executeRawUnsafe(`PRAGMA foreign_keys = OFF`)

// Delete tables except the ones that are excluded above
for (const { name } of tables) {
await prisma.$executeRawUnsafe(`DROP TABLE IF EXISTS "${name}"`)
}
await prisma.$transaction([
...tables.map(({ name }) =>
prisma.$executeRawUnsafe(`DROP TABLE IF EXISTS "${name}"`),
),
])

const migrationPaths = fs
.readdirSync('prisma/migrations')
Expand All @@ -143,16 +145,11 @@ export async function cleanupDb(prisma: PrismaClient) {
.filter(Boolean)

// Run each sql statement in the migration
await prisma.$transaction(async (tx) => {
for (const statement of statements) {
try {
await tx.$executeRawUnsafe(`${statement}`)
} catch (error) {
console.warn(`Failed to execute statement: ${statement}`)
throw error
}
}
})
await prisma.$transaction([
...statements.map((statement) =>
prisma.$executeRawUnsafe(`${statement}`),
),
])
}
} catch (error) {
console.error('Error cleaning up database:', error)
Expand Down

0 comments on commit e279227

Please sign in to comment.