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
|
@ -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"
|
||||||
|
|
|
@ -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')
|
||||||
dbtools.Insert(authDB, 'users', {
|
|
||||||
pw: 2,
|
uids.forEach((cid, i) => {
|
||||||
notes: 'hemnlo'
|
logger.Log(`[ ${i} / ${uids.length} ]`)
|
||||||
})
|
try {
|
||||||
dbtools.Insert(authDB, 'users', {
|
dbtools.Insert(authDB, 'users', {
|
||||||
pw: 1,
|
pw: uuidv4(),
|
||||||
notes: 'hemnlo'
|
oldCID: cid
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
logger.Log('Error during inserting', logger.GetColor('redbg'))
|
||||||
|
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()
|
|
||||||
|
|
|
@ -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]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue