Skip to content

Commit

Permalink
backup db should be in its own directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinse12 committed Nov 4, 2024
1 parent 892a345 commit 73b6266
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/runtime/node/subplebbit/db-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 73b6266

Please sign in to comment.