1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-05 19:05:18 +02:00

Server db utils changes

This commit is contained in:
Paweł Malak 2021-11-13 23:28:43 +01:00
parent 91e99e1bcc
commit d86ebe3e58
5 changed files with 36 additions and 21 deletions

View file

@ -1,12 +1,12 @@
const fs = require('fs');
const { slugify } = require('./slugify');
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 slug = slugify();
const srcPath = 'data/db.sqlite';
const destPath = `data/db_backups/${slug}`;

19
db/utils/slugify.js Normal file
View file

@ -0,0 +1,19 @@
const slugify = () => {
const version = process.env.VERSION;
const slug = `db-${version.replace(/\./g, '')}-backup.sqlite`;
return slug;
};
const parseSlug = (slug) => {
const parts = slug.split('-');
const version = {
raw: parts[1],
parsed: parts[1].split('').join('.'),
};
return version;
};
module.exports = {
slugify,
parseSlug,
};