nationalcollegiateesports / discord-bot

MIT License
2 stars 0 forks source link

Database for per-server configuration #5

Closed themaxdavitt closed 3 years ago

themaxdavitt commented 3 years ago

The bot needs a central database for storing persistent stuff - server configuration, user verifications, polls and other events that take place over time, etc. Something like MongoDB would probably work well as it scales well and doesn't require a lot of overhead or special setup for a JS implementation.

eritbh commented 3 years ago

For reference, MongoDB is a document-based database, rather than a relational one like SQL-based databases, though it has many analogous features. A MongoDB database is made up of collections of JSON-like documents, similar to tables and rows in an SQL database, except that the type of data stored in each collection doesn't need to be set up ahead of time; you can insert basically any document into any collection (though you can still set up document validation per-collection if needed). MongoDB also has features such as change streams, which let you have the database tell your code when something in the database changes. What is MongoDB? is a good resource from their website if you're new to it.

The way I'd do it, any bot feature that needs to store data in the database would use its own collections, rather than e.g. having one big "guild config" collection that stores all the configuration for each guild in one place. This will help prevent code in one area of the bot from accidentally messing with data in another area, except when it's specifically required.

For example, the database structure for the verification feature might look something like this:

themaxdavitt commented 3 years ago

I'm not very experienced with MongoDB, but the way you described seems like it would be a really good fit for this. I was looking over important schema design patterns as so long as we're ensuring we're following them (especially the schema versioning one), this will allow us a lot of flexibility in how we develop the bot.

Also, I wasn't really thinking about it at the time but it would make the most sense for us to combine all the architecture-related issues into one so we can easily look at how everything should fit together in one place. I'm closing this in favor of #9.