Tool to automate assignment of articles, manage summaries, provide an API for content and sharing them on @scribeDAO. If you have any questions or want to help out join us on Discord #automation
Getting Started
Want to help out? Let's setup this project!
Prerequisites
Recommended
Running this project
- Clone the repository
- Run
yarn
to install dependencies - Copy
.env.local.example
to.env
and fill in the values - You will need a MySQL database. You can:
- Install MySQL locally OR
- Run it in a docker container. There is a
db/docker-compose.yml
. You can runcd db && docker-compose pull
to install and thenyarn start:db
to start the server. OR - Use a remote database service like planetscale
- You need to also fill in the
.env
file Discord Credentials. You can get those from the ScribeDAO App on Discord Developer Portal - Run
yarn dev
to start the server and open the browser. Happy coding!
Design and Architecture
- For Database we use MySQL (that is what planetscale offers currently).
- Prisma v2 ORM is used.
- You can find database schema in
prisma/schema.prisma
. There is a DBML version inprisma/dbml/schema.dbml
also generated which you can use to visualize the schema in DB Diagram/
- You can find database schema in
Login Flow
- User logs in with discord
- We use our Bot to check if the users is in our server
- Then we check if the user has Knowledge Seeker or above role, if so they are logged in.
- When user account is created and linked in DB we grab user's roles from Discord and link them to user in DB.
- Flaws: If user's role is updated we can't automatically update in DB. Read more in this issue #5
Deploying to Production
We use Vercel to deploy this project to production. We have GitHub Actions to deploy to production. For database Vercel will connect to MySQL instance running in planetscale
Applying DB migrations
We use prisma db push
to apply migrations. See prisma/prisma#9703 (comment). Please do not apply migrations in production.
- Login to PlanetScale
pscale login
- Create 2 branches from
main
one feature branch and othershadow
pscale branch create scribedao-prod <FEATURE_NAME>
pscale branch create scribedao-prod shadow
- Now connect to the branches so you can connect to DB locally.
pscale connect scribedao-prod <FEATURE_NAME> --port 3309
pscale connect scribedao-prod shadow --port 3310
- Now apply new migrations
yarn prisma db push
- Create a Deploy request (kinda like a PR but for DB)
pscale deploy-request create scribedao-prod <FEATURE_NAME>
- Now just need to merge your code on GitHub and apply those DB changes and we are done!
Applying seed data or making changes using prisma studio
WARNING: You will be connecting and updating prod database
- Create a
shadow
branch frommain
pscale branch create scribedao-prod shadow
- Now connect to the branches so you can connect to DB locally.
pscale connect scribedao-prod main --port 3309
pscale connect scribedao-prod shadow --port 3310
yarn prisma db seed
- You can view your change in prisma studio
yarn prisma studio
Create a branch with Prod data
- Get the latest backup
pscale backup list scribedao-prod main
- Create new branch
pscale backup restore scribedao-prod dev <BACKUP_ID>
pscale backup restore scribedao-prod shadow <BACKUP_ID>
More: planetscale/discussion#112
Monitoring
We use Sentry for errors and performance monitoring.
Note: currently this is on personal account we need to move to Open Source account.
Learn More
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Prisma Documentation
- NextAuth.js
v3
- PlanetScale applying prisma migrations