dbSetup import cids

This commit is contained in:
MrFry 2020-04-07 09:41:00 +02:00
parent 131577f25b
commit fb8e12f8d2
3 changed files with 46 additions and 15 deletions

View file

@ -11,6 +11,9 @@
"notNull": true, "notNull": true,
"unique": true "unique": true
}, },
"oldCID": {
"type": "text"
},
"lastIP": { "lastIP": {
"type": "text" "type": "text"
}, },
@ -18,7 +21,8 @@
"type": "text" "type": "text"
}, },
"loginCount": { "loginCount": {
"type": "number" "type": "number",
"defaultZero": true
}, },
"lastLogin": { "lastLogin": {
"type": "text" "type": "text"

View file

@ -1,12 +1,15 @@
const utils = require('../utils/utils.js') const utils = require('../utils/utils.js')
const logger = require('../utils/logger.js')
const dbtools = require('../utils/dbtools.js') const dbtools = require('../utils/dbtools.js')
const dbStructPath = '../modules/api/apiDBStruct.json' const dbStructPath = '../modules/api/apiDBStruct.json'
const usersDBPath = '../data/dbs/users.db' const usersDBPath = '../data/dbs/users.db'
const uuidv4 = require('uuid/v4') // TODO: deprecated, but imports are not supported
let authDB let authDB
console.clear() console.clear()
CreateDB()
function CreateDB () { function CreateDB () {
const dbStruct = utils.ReadJSON(dbStructPath) const dbStruct = utils.ReadJSON(dbStructPath)
@ -18,22 +21,45 @@ function CreateDB () {
}) })
try { try {
// TODO: fill with data const uids = utils.ReadFile('../dbUsers/keys').split('\n')
uids.forEach((cid, i) => {
logger.Log(`[ ${i} / ${uids.length} ]`)
try {
dbtools.Insert(authDB, 'users', { dbtools.Insert(authDB, 'users', {
pw: 2, pw: uuidv4(),
notes: 'hemnlo' oldCID: cid
}) })
dbtools.Insert(authDB, 'users', { } catch (e) {
pw: 1, logger.Log('Error during inserting', logger.GetColor('redbg'))
notes: 'hemnlo' console.error(e)
}
}) })
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
// Object.keys(dbStruct).forEach((key) => { const dir = `./dbSetupResult/${GetDateString().replace(/ /g, '_')}`
// console.log(key) utils.CreatePath(dir)
// console.log(dbtools.TableInfo(authDB, key)) 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()

View file

@ -124,7 +124,8 @@ function CreateTable (db, name, columns, foreignKeys) {
primary: 'PRIMARY KEY', primary: 'PRIMARY KEY',
notNull: 'NOT NULL', notNull: 'NOT NULL',
unique: 'UNIQUE', unique: 'UNIQUE',
autoIncrement: 'AUTOINCREMENT' autoIncrement: 'AUTOINCREMENT',
defaultZero: 'DEFAULT 0'
} }
Object.keys(toCheck).forEach((key) => { Object.keys(toCheck).forEach((key) => {
if (item[key]) { if (item[key]) {