1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-24 13:39:35 +02:00

Create database backup before migrating

This commit is contained in:
unknown 2021-10-05 13:17:09 +02:00
parent 84bd641cf2
commit 59271d3376
3 changed files with 25 additions and 4 deletions

21
db/utils/backupDb.js Normal file
View file

@ -0,0 +1,21 @@
const fs = require('fs');
const backupDB = () => {
if (!fs.existsSync('data/db_backups')) {
fs.mkdirSync('data/db_backups');
}
const version = process.env.VERSION;
const slug = `db-${version.replace(/\./g, '')}-backup.sqlite`;
const srcPath = 'data/db.sqlite';
const destPath = `data/db_backups/${slug}`;
if (fs.existsSync(srcPath)) {
if (!fs.existsSync(destPath)) {
fs.copyFileSync(srcPath, destPath);
}
}
};
module.exports = backupDB;