From 41fd3292b397b8e4d1280d6e54d13dae0f1af323 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 18 Jul 2025 16:42:53 +0000 Subject: [PATCH] Handle database file cleanup before seeding playground Co-authored-by: me --- epicshop/post-set-playground.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/epicshop/post-set-playground.js b/epicshop/post-set-playground.js index 8c5ebc1..4772e3c 100644 --- a/epicshop/post-set-playground.js +++ b/epicshop/post-set-playground.js @@ -1,19 +1,29 @@ import { existsSync } from 'node:fs' +import { unlink } from 'node:fs/promises' import { join } from 'node:path' import { execa } from 'execa' -const seedPath = join( - process.env.EPICSHOP_PLAYGROUND_DEST_DIR, - 'src', - 'db', - 'seed.ts', -) +const playgroundDir = process.env.EPICSHOP_PLAYGROUND_DEST_DIR +const seedPath = join(playgroundDir, 'src', 'db', 'seed.ts') + +// Delete the database file if it exists to prevent EBUSY errors when switching playgrounds +const dbPath = join(playgroundDir, 'db.sqlite') +if (existsSync(dbPath)) { + console.log('Deleting existing database file...') + try { + await unlink(dbPath) + console.log('Database file deleted successfully') + } catch (error) { + console.warn('Failed to delete database file:', error.message) + // Continue anyway - the seed script will also try to delete it + } +} if (existsSync(seedPath)) { console.log('Running seed script...') try { await execa('npx', ['tsx', seedPath], { - cwd: process.env.EPICSHOP_PLAYGROUND_DEST_DIR, + cwd: playgroundDir, stdio: 'inherit', }) console.log('Seed script completed successfully')