diff options
| author | Pitu <[email protected]> | 2021-01-04 01:04:20 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2021-01-04 01:04:20 +0900 |
| commit | fcd39dc550dec8dbcb8325e07e938c5024cbc33d (patch) | |
| tree | f41acb4e0d5fd3c3b1236fe4324b3fef9ec6eafe /src/api/database/seeds/initial.js | |
| parent | Create FUNDING.yml (diff) | |
| parent | chore: update todo (diff) | |
| download | host.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.tar.xz host.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.zip | |
Merge branch 'dev'
Diffstat (limited to 'src/api/database/seeds/initial.js')
| -rw-r--r-- | src/api/database/seeds/initial.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/api/database/seeds/initial.js b/src/api/database/seeds/initial.js new file mode 100644 index 0000000..edc1949 --- /dev/null +++ b/src/api/database/seeds/initial.js @@ -0,0 +1,30 @@ +/* eslint-disable no-console */ +const bcrypt = require('bcrypt'); +const moment = require('moment'); + +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; + try { + const hash = await bcrypt.hash(process.env.ADMIN_PASSWORD, 10); + await db.table('users').insert({ + username: process.env.ADMIN_ACCOUNT, + password: hash, + passwordEditedAt: now, + createdAt: now, + editedAt: now, + enabled: true, + isAdmin: true + }); + console.log(); + console.log('========================================================='); + console.log('== Successfully created the admin account. =='); + console.log('========================================================='); + console.log('== Run `pm2 start pm2.json` to start the service =='); + console.log('========================================================='); + console.log(); + } catch (error) { + console.error(error); + } +}; |