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

@ -7,19 +7,13 @@
Flame is self-hosted startpage for your server. Its design is inspired (heavily) by [SUI](https://github.com/jeroenpardon/sui). Flame is very easy to setup and use. With built-in editors, it allows you to setup your very own application hub in no time - no file editing necessary. Flame is self-hosted startpage for your server. Its design is inspired (heavily) by [SUI](https://github.com/jeroenpardon/sui). Flame is very easy to setup and use. With built-in editors, it allows you to setup your very own application hub in no time - no file editing necessary.
## Functionality ## Functionality
📝 Create, update, delete your applications and bookmarks directly from the app using built-in GUI editors - 📝 Create, update, delete your applications and bookmarks directly from the app using built-in GUI editors
- 📌 Pin your favorite items to the homescreen for quick and easy access
📌 Pin your favorite items to the homescreen for quick and easy access - 🔍 Integrated search bar with local filtering, 11 web search providers and ability to add your own
- 🔑 Authentication system to protect your settings, apps and bookmarks
🔍 Integrated search bar with local filtering, 11 web search providers and ability to add your own - 🔨 Dozens of option to customize Flame interface to your needs, including support for custom CSS and 15 built-in color themes
- ☀️ Weather widget with current temperature, cloud coverage and animated weather status
🔑 Authentication system to protect your settings, apps and bookmarks - 🐳 Docker integration to automatically pick and add apps based on their labels
🔨 Dozens of option to customize Flame interface to your needs, including support for custom CSS and 15 built-in color themes
☀️ Weather widget with current temperature, cloud coverage and animated weather status
🐳 Docker integration to automatically pick and add apps based on their labels
## Installation ## Installation
@ -55,7 +49,7 @@ docker buildx build \
```sh ```sh
# run container # run container
docker run -p 5005:5005 -v /path/to/data:/app/data flame docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password flame
``` ```
#### Docker-Compose #### Docker-Compose
@ -124,7 +118,7 @@ npm run dev
![Settings screenshot](.github/settings.png) ![Settings screenshot](.github/settings.png)
![Themes screenshot](.github/_themes.png) ![Themes screenshot](.github/themes.png)
## Usage ## Usage

View file

@ -1,8 +1,9 @@
const { Sequelize } = require('sequelize'); const { Sequelize } = require('sequelize');
const { join } = require('path'); const { join } = require('path');
const Umzug = require('umzug'); const Umzug = require('umzug');
const backupDB = require('./utils/backupDb');
// Utils
const backupDB = require('./utils/backupDb');
const Logger = require('../utils/Logger'); const Logger = require('../utils/Logger');
const logger = new Logger(); const logger = new Logger();
@ -28,15 +29,16 @@ const connectDB = async () => {
backupDB(); backupDB();
await sequelize.authenticate(); await sequelize.authenticate();
logger.log('Connected to database');
// migrations // execute all pending migrations
const pendingMigrations = await umzug.pending(); const pendingMigrations = await umzug.pending();
if (pendingMigrations.length > 0) { if (pendingMigrations.length > 0) {
logger.log('Executing pending migrations'); logger.log('Executing pending migrations');
await umzug.up(); await umzug.up();
} }
logger.log('Connected to database');
} catch (error) { } catch (error) {
logger.log(`Unable to connect to the database: ${error.message}`, 'ERROR'); logger.log(`Unable to connect to the database: ${error.message}`, 'ERROR');
process.exit(1); process.exit(1);

View file

@ -1,12 +1,12 @@
const fs = require('fs'); const fs = require('fs');
const { slugify } = require('./slugify');
const backupDB = () => { const backupDB = () => {
if (!fs.existsSync('data/db_backups')) { if (!fs.existsSync('data/db_backups')) {
fs.mkdirSync('data/db_backups'); fs.mkdirSync('data/db_backups');
} }
const version = process.env.VERSION; const slug = slugify();
const slug = `db-${version.replace(/\./g, '')}-backup.sqlite`;
const srcPath = 'data/db.sqlite'; const srcPath = 'data/db.sqlite';
const destPath = `data/db_backups/${slug}`; 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,
};

View file

@ -20,9 +20,9 @@ const logger = new Logger();
const PORT = process.env.PORT || 5005; const PORT = process.env.PORT || 5005;
// Init app // Init app
await initApp();
await connectDB(); await connectDB();
await associateModels(); await associateModels();
await initApp();
// Create server for Express API and WebSockets // Create server for Express API and WebSockets
const server = http.createServer(); const server = http.createServer();