aboutsummaryrefslogtreecommitdiff
path: root/src/api/database/seeds/initial.js
diff options
context:
space:
mode:
authorKana <[email protected]>2021-06-19 02:03:57 +0900
committerGitHub <[email protected]>2021-06-19 02:03:57 +0900
commit065c5221a0250838f1d1f9bb7a7922ff4f55e038 (patch)
tree8a69a81f00e6bff2752f4f7c59dcbbf21f893b20 /src/api/database/seeds/initial.js
parentchore: docs update (diff)
parentfix: potentially fix the blocked extensions array splitting (diff)
downloadhost.fuwn.me-065c5221a0250838f1d1f9bb7a7922ff4f55e038.tar.xz
host.fuwn.me-065c5221a0250838f1d1f9bb7a7922ff4f55e038.zip
Merge pull request #278 from Zephyrrus/Zephyrrus-feature/database_based_settings
Zephyrrus feature/database based settings
Diffstat (limited to 'src/api/database/seeds/initial.js')
-rw-r--r--src/api/database/seeds/initial.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/api/database/seeds/initial.js b/src/api/database/seeds/initial.js
index edc1949..7c04dad 100644
--- a/src/api/database/seeds/initial.js
+++ b/src/api/database/seeds/initial.js
@@ -1,15 +1,41 @@
/* eslint-disable no-console */
const bcrypt = require('bcrypt');
const moment = require('moment');
+const Util = require('../../utils/Util');
exports.seed = async db => {
const now = moment.utc().toDate();
- const user = await db.table('users').where({ username: process.env.ADMIN_ACCOUNT }).first();
- if (user) return;
+
+ // Save environment variables to the database
+ try {
+ const defaults = Util.getEnvironmentDefaults();
+ const keys = Object.keys(defaults);
+ for (const item of keys) {
+ await Util.writeConfigToDb({
+ key: item,
+ value: defaults[item]
+ });
+ }
+ } catch (error) {
+ console.error(error);
+ }
+
+ // Create admin user if it doesnt exist
+ const user = await db.table('users').where({ username: 'admin' }).first();
+ if (user) {
+ console.log();
+ console.log('=========================================================');
+ console.log('== admin account already exists, skipping. ==');
+ console.log('=========================================================');
+ console.log('== Run `pm2 start pm2.json` to start the service ==');
+ console.log('=========================================================');
+ console.log();
+ return;
+ }
try {
- const hash = await bcrypt.hash(process.env.ADMIN_PASSWORD, 10);
+ const hash = await bcrypt.hash('admin', 10);
await db.table('users').insert({
- username: process.env.ADMIN_ACCOUNT,
+ username: 'admin',
password: hash,
passwordEditedAt: now,
createdAt: now,