Skip to content

Commit e279227

Browse files
committed
Try map
1 parent a411a4a commit e279227

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

tests/db-utils.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ export async function cleanupDb(prisma: PrismaClient) {
125125
await prisma.$executeRawUnsafe(`PRAGMA foreign_keys = OFF`)
126126

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

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

145147
// Run each sql statement in the migration
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-
}
154-
}
155-
})
148+
await prisma.$transaction([
149+
...statements.map((statement) =>
150+
prisma.$executeRawUnsafe(`${statement}`),
151+
),
152+
])
156153
}
157154
} catch (error) {
158155
console.error('Error cleaning up database:', error)

0 commit comments

Comments
 (0)