Skip to content

Instantly share code, notes, and snippets.

@TheEssem
Created September 9, 2023 19:13
Show Gist options
  • Save TheEssem/2c918812361d34361cf17d8877ae10cf to your computer and use it in GitHub Desktop.
Save TheEssem/2c918812361d34361cf17d8877ae10cf to your computer and use it in GitHub Desktop.
An ancient migration script from back when esmBot was switching to MongoDB, uploading here so it isn't lost forever
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/esmBot");
module.exports = async (client) => {
const settings = client.settings;
const tags = client.tags;
const guildSchema = new mongoose.Schema({
id: String,
tags: Map,
prefix: String
});
const Guild = mongoose.model("Guild", guildSchema);
console.log(settings);
const indexes = settings.indexes;
for (const i of indexes) {
const serverSettings = settings.get(i);
const serverTags = tags.get(i);
console.log(serverTags);
const guild = new Guild({
id: i,
tags: serverTags,
prefix: serverSettings.prefix
});
guild.save((error) => {
if (error) throw error;
console.log(`Migrated guild ${i}`);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment