mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
dbSetup import cids
This commit is contained in:
parent
131577f25b
commit
fb8e12f8d2
3 changed files with 46 additions and 15 deletions
|
@ -1,12 +1,15 @@
|
|||
|
||||
const utils = require('../utils/utils.js')
|
||||
const logger = require('../utils/logger.js')
|
||||
const dbtools = require('../utils/dbtools.js')
|
||||
const dbStructPath = '../modules/api/apiDBStruct.json'
|
||||
const usersDBPath = '../data/dbs/users.db'
|
||||
const uuidv4 = require('uuid/v4') // TODO: deprecated, but imports are not supported
|
||||
|
||||
let authDB
|
||||
|
||||
console.clear()
|
||||
CreateDB()
|
||||
|
||||
function CreateDB () {
|
||||
const dbStruct = utils.ReadJSON(dbStructPath)
|
||||
|
@ -18,22 +21,45 @@ function CreateDB () {
|
|||
})
|
||||
|
||||
try {
|
||||
// TODO: fill with data
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 2,
|
||||
notes: 'hemnlo'
|
||||
})
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 1,
|
||||
notes: 'hemnlo'
|
||||
const uids = utils.ReadFile('../dbUsers/keys').split('\n')
|
||||
|
||||
uids.forEach((cid, i) => {
|
||||
logger.Log(`[ ${i} / ${uids.length} ]`)
|
||||
try {
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: uuidv4(),
|
||||
oldCID: cid
|
||||
})
|
||||
} catch (e) {
|
||||
logger.Log('Error during inserting', logger.GetColor('redbg'))
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
// Object.keys(dbStruct).forEach((key) => {
|
||||
// console.log(key)
|
||||
// console.log(dbtools.TableInfo(authDB, key))
|
||||
// })
|
||||
const dir = `./dbSetupResult/${GetDateString().replace(/ /g, '_')}`
|
||||
utils.CreatePath(dir)
|
||||
Object.keys(dbStruct).forEach((key) => {
|
||||
const path = `${dir}/${key}.json`
|
||||
logger.Log(`Writing ${path}...`)
|
||||
utils.WriteFile(JSON.stringify({
|
||||
tableInfo: dbtools.TableInfo(authDB, key),
|
||||
tableRows: dbtools.SelectAll(authDB, key)
|
||||
}), path)
|
||||
})
|
||||
|
||||
logger.Log('Done')
|
||||
}
|
||||
|
||||
function GetDateString () {
|
||||
const m = new Date()
|
||||
const d = m.getFullYear() + '-' +
|
||||
('0' + (m.getMonth() + 1)).slice(-2) + '-' +
|
||||
('0' + m.getDate()).slice(-2) + ' ' +
|
||||
('0' + m.getHours()).slice(-2) + ':' +
|
||||
('0' + m.getMinutes()).slice(-2) + ':' +
|
||||
('0' + m.getSeconds()).slice(-2)
|
||||
return d
|
||||
}
|
||||
CreateDB()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue