forked from jmiln/SWGoHBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbRework.js
More file actions
53 lines (46 loc) · 1.68 KB
/
Copy pathdbRework.js
File metadata and controls
53 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Sequelize = require("sequelize");
const { inspect } = require("util");
const momentTZ = require("moment-timezone");
const config = require("./config.js");
/* eslint no-unused-vars: 0 */
const init = async function() {
const MongoClient = require("mongodb").MongoClient;
const mongo = await MongoClient.connect("mongodb://localhost:27017/", { useNewUrlParser: true } );
const cache = await require("./modules/cache.js")(mongo);
const sequelize = new Sequelize(config.database.data, config.database.user, config.database.pass, {
host: config.database.host,
dialect: "postgres",
logging: false,
operatorAliases: false
});
const allyCodes = sequelize.define("allyCodes", {
id: {
type: Sequelize.TEXT,
primaryKey: true
},
allyCode: {
type: Sequelize.BIGINT
}
});
await allyCodes.sync();
const oldAllyCodes = await allyCodes.findAll();
for (const ac of oldAllyCodes) {
const a = ac.dataValues;
const defSettings = JSON.parse(JSON.stringify(config.defaultUserConf));
user.id = a.id;
let player = await mongo.db("swapi").collection("players").find({allyCode: parseInt(a.allyCode)}).toArray();
if (Array.isArray(player) && player.length) player = player[0];
user.accounts = [{
allyCode: a.allyCode,
name: player && player.name ? player.name : null,
primary: true
}];
await mongo.db("swgohbot").collection("users").updateOne({id: a.id},
{$set: user},
{upsert: true}
);
user = null;
}
console.log("Done");
};
init();