Browse Source

Add legacy json file upgrader

master
benji7425 3 years ago
parent
commit
041c3464f9
  1. 1
      app/index.js
  2. 28
      app/legacy-upgrader.js

1
app/index.js

@ -24,6 +24,7 @@ client.on("beforeLogin", () =>
client.on("ready", () => {
parseLinksInGuilds().then(doGuildIteration);
require("./legacy-upgrader.js")(); //upgrade legacy json into new database format
});
client.on("message", message => {

28
app/legacy-upgrader.js

@ -0,0 +1,28 @@
const NewGuildData = require("./models/guild-data.js");
const NewFeedData = require("./models/feed-data.js");
const FileSystem = require("fs");
module.exports = function () {
if (!FileSystem.existsSync("./guilds.json"))
return;
const legacyJson = require("../guilds.json");
for (let guildID of Object.keys(legacyJson)) {
const guildData = NewGuildData.create({ guildID });
for (let feed of legacyJson[guildID].feeds) {
guildData.feeds.push(NewFeedData.create({
feedID: feed.id,
url: feed.url,
roleID: feed.roleID,
cachedLinks: feed.cachedLinks,
maxCacheSize: feed.maxCacheSize
}));
}
guildData.save();
}
FileSystem.unlinkSync("./guilds.json");
};
Loading…
Cancel
Save