From 73b62660b6f34931f130276db10d2bca24772ba4 Mon Sep 17 00:00:00 2001 From: Rinse Date: Mon, 4 Nov 2024 14:06:31 +0000 Subject: [PATCH] backup db should be in its own directory --- src/runtime/node/subplebbit/db-handler.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runtime/node/subplebbit/db-handler.ts b/src/runtime/node/subplebbit/db-handler.ts index a034b7d2..ba808102 100644 --- a/src/runtime/node/subplebbit/db-handler.ts +++ b/src/runtime/node/subplebbit/db-handler.ts @@ -311,9 +311,16 @@ export class DbHandler { let backupDbPath: string | undefined; const dbExistsAlready = fs.existsSync(dbPath); if (needToMigrate) { - if (dbExistsAlready) { + if (dbExistsAlready && currentDbVersion > 0) { await this.destoryConnection(); - backupDbPath = dbPath + `.backup-migration.${currentDbVersion}.${timestamp()}`; + backupDbPath = path.join( + path.dirname(dbPath), + ".backup_before_migration", + `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}` + ); + log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`); + + await fs.promises.mkdir(path.dirname(backupDbPath)); await fs.promises.cp(dbPath, backupDbPath); await this.initDestroyedConnection(); }