Skip to content

Commit a411a4a

Browse files
committed
Wrap statement execution in a transaction
1 parent 3fbaa78 commit a411a4a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tests/db-utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ export async function cleanupDb(prisma: PrismaClient) {
143143
.filter(Boolean)
144144

145145
// Run each sql statement in the migration
146-
for (const statement of statements) {
147-
try {
148-
await prisma.$executeRawUnsafe(`${statement};`)
149-
} catch (error) {
150-
console.warn(`Failed to execute statement: ${statement}`)
151-
throw error
146+
await prisma.$transaction(async (tx) => {
147+
for (const statement of statements) {
148+
try {
149+
await tx.$executeRawUnsafe(`${statement}`)
150+
} catch (error) {
151+
console.warn(`Failed to execute statement: ${statement}`)
152+
throw error
153+
}
152154
}
153-
}
155+
})
154156
}
155157
} catch (error) {
156158
console.error('Error cleaning up database:', error)

0 commit comments

Comments
 (0)