Skip to content

Commit 1f2a287

Browse files
Handle database file cleanup before seeding playground (#5)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 6d1583c commit 1f2a287

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

epicshop/post-set-playground.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import { existsSync } from 'node:fs'
2+
import { unlink } from 'node:fs/promises'
23
import { join } from 'node:path'
34
import { execa } from 'execa'
45

5-
const seedPath = join(
6-
process.env.EPICSHOP_PLAYGROUND_DEST_DIR,
7-
'src',
8-
'db',
9-
'seed.ts',
10-
)
6+
const playgroundDir = process.env.EPICSHOP_PLAYGROUND_DEST_DIR
7+
const seedPath = join(playgroundDir, 'src', 'db', 'seed.ts')
8+
9+
// Delete the database file if it exists to prevent EBUSY errors when switching playgrounds
10+
const dbPath = join(playgroundDir, 'db.sqlite')
11+
if (existsSync(dbPath)) {
12+
console.log('Deleting existing database file...')
13+
try {
14+
await unlink(dbPath)
15+
console.log('Database file deleted successfully')
16+
} catch (error) {
17+
console.warn('Failed to delete database file:', error.message)
18+
// Continue anyway - the seed script will also try to delete it
19+
}
20+
}
1121

1222
if (existsSync(seedPath)) {
1323
console.log('Running seed script...')
1424
try {
1525
await execa('npx', ['tsx', seedPath], {
16-
cwd: process.env.EPICSHOP_PLAYGROUND_DEST_DIR,
26+
cwd: playgroundDir,
1727
stdio: 'inherit',
1828
})
1929
console.log('Seed script completed successfully')

0 commit comments

Comments
 (0)