Skip to content

Commit

Permalink
fix: don't create copy if memory
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed May 31, 2022
1 parent 2dd3f9d commit a89627e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/database/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export class DatabaseManager extends DatabaseDemuxBase {
} catch (err) {
console.error(err);
await this.db!.close();
await fs.copyFile(copyPath, dbPath);
copyPath && (await fs.copyFile(copyPath, dbPath));
throw err;
} finally {
await fs.unlink(copyPath);
copyPath && (await fs.unlink(copyPath));
}
}

Expand Down Expand Up @@ -154,6 +154,10 @@ export class DatabaseManager extends DatabaseDemuxBase {

async #makeTempCopy() {
const src = this.db!.dbPath;
if (src === ':memory:') {
return null;
}

const dir = path.parse(src).dir;
const dest = path.join(dir, '__premigratory_temp.db');
await fs.copyFile(src, dest);
Expand Down
4 changes: 4 additions & 0 deletions backend/patches/updateSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const defaultNumberSeriesMap = {
} as Record<ModelNameEnum, string>;

async function execute(dm: DatabaseManager) {
if (dm.db?.dbPath === ':memory:') {
return;
}

const sourceKnex = dm.db!.knex!;
const version = (
await sourceKnex('SingleValue')
Expand Down

0 comments on commit a89627e

Please sign in to comment.