-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: implement PostgreSQL for storage of per-server settings #19
Conversation
- added postgres service to docker-compose - started using Docker secrets to manage database password, bot token - add barebones "configure" command to experiment with commands - installed and configured pgtyped
realized I accidentally deleted .eslintrc with the previous commit so I took some time to re-configure it to properly work with all the files in our repo - update .eslintrc.js - add prettier config and ignore files - update pre-commit configuration to parity with eslintrc and prettierrc
- move prettier and eslint to separate jobs within the same workflow - use actions/setup-node's built in caching instead of a manual step
using .mts was a folley... instead, it appears we need to prepend import statements in *.queries.ts files with `// @ts-expect-error moduleResolution`
we were using this functionality for getting the Discord token, we will also use this for getting the database password.
- make `id` columns properly autoincrement - flesh out table relations - add "pg" and "@types/pg" dependencies
I *think* this will allow for easy access to the database with the IP `postgres.docker`
- dropped PgTyped and related files - set up pg for raw Postgres queries - catch Ctrl+C SIGTERM so we can cleanly shut down database connections - add pgPool member to Discord Client instance - update linter configs to reflect dropping PgTyped
- docker-compose: Use a shared array of environment variables in docker compose - discord-bot: Run a test command on startup to check our database
we're going to store all the database logic in src/bot/database. also flesh out the CustomPool object to add event handlers.
- delete seed/index.ts (don't need to initialize db in software) - rename seed/ to initdb/ - change initdb path in docker-compose - use smaller postgres:16-alpine image in docker-compose
man oh man it's ugly as sin but I got some database crap working. next step is to abstract db logic out into its own files to simplify application command code.
makes merging in from main easier
problems to solve: - abstract database logic out to src/bot/database - build paramaterized query strings with DEFAULT (cannot pass DEFAULT in a parameter... just pass same value we got back from the db?) - finally get around to parsing all those boolean options from the command
wholly crap lois whole lotta bug testing I gotta do on this. also introduced some issues with AppCommandsCLI but I should really break that out into its own module anyway
It's possible to set permissions for a command using e.g. new SlashCommandBuilder()
.setName(...)
// ...
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator) should make the command admin-only. |
Should Also FYI: |
Summary
As LinkFix gets added to more servers, several people have reached out requesting features that would require per-server configuration. We need to store those configurations.
Methodology
Firstly, I am going to try to avoid using ORMs as much as possible. the
pg
package offers the ability to execute raw queries which should be good enough for our requirements. If, in the future, the database gets more complicated, I wouldn't have an issue moving to something like Sequelize.Secondly, I want LinkFix to store as little data as possible. I think we shouldn't create records for guilds until someone in the guild actually sets configuration options. This keeps us in the clear for crap like GDPR, plus I personally believe in data privacy myself and don't want to become a vector of attack for other people.
Database Structire
https://dbdiagram.io/d/LinkFix-658b15e289dea6279992fb74
To-Do
/configure
command to get and store settings/forget
command to wipe guild from databaseAfter we move into production: