* feat: move community supabase request to api layer * chore: pr review checkpoint * chore: PR fixes * feat: implement role-based authorization middleware and align the community features with the developer guide. - Added role-based authorization middleware for organization and course membership checks, including `orgMemberMiddleware`, `orgTeamMemberMiddleware`, and `courseMemberMiddleware`. - Introduced route-specific middleware for comment and question authorization, ensuring only authors or team members can modify content. - Updated community routes to utilize the new middleware for enhanced security and access control. - Refactored community services to streamline upvote functionality and improve error handling. - Enhanced UI components for community interactions, including new comment and question pages, and improved state management for user actions. - Updated documentation to reflect new middleware usage and best practices for authorization in the API layer. * feat: enhance course and organization routes with middleware for improved access control - Added `courseMemberMiddleware` to course download and clone routes to enforce membership checks. - Updated lesson route to include `courseMemberMiddleware` for PDF downloads. - Integrated `orgMemberMiddleware` into organization routes for team and audience access, ensuring only authorized members can retrieve data. - Refactored lesson and organization routes for consistency and clarity in middleware usage. * chore: streamline dashboard and API development scripts in package.json - Consolidated dashboard and API development commands to include all relevant filters in a single line for improved clarity and ease of use. - Removed redundant full command variants to simplify the script section. --------- Co-authored-by: Rotimi Best <best@classroomio.com>
@cio/db
This package handles everything related to the database, schema, migrations and connection.
Stack
- Postgres - We use postgres for the database
- Drizzle ORM - For managing and querying the database
- Better Auth - For managing the auth tables (users, account, session).
Workflow
We used Supabase in the past for managing the supabase but have now moved on to use postgres directly and auth managed by our backend. This means the workflow is a mix of the Database First approach (Option 1) and the Codebase First approach (Option 2). Learn more about each approach from the drizzle migration docs.
Here is how I do it:
1. Local DB to Drizzle Schema TS file
I have a postgres tool where I can make changes to the db as I want. I am not so familiar with drizzle that much so I am sticking with this for now.
```bash
pnpm db pull # this does sql -> drizzle ts code
```
2. Drizzle Schema file to Prod SQL
Now when I am ready to deploy the feature, I can use option 2 which is makes the typescript schema the source of truth. This command will only run on CI on every merge on a condition that there was a change to the schema file packages/db/src/schema.ts
```bash
pnpm db push # this does drizzle ts code to prod db
```
OR
I can make changes directly to the schema file and run pnpm db push to push the changes to the source db.
Change email flow
- User changes email on dashboard to new email
- We send an email verification to the current, permitting the change
- Meanwhile the frontend reverts to the previous email.
- User clicks approve link in email
- User is redirected to settings page with message that another email has been sent to the new email
- User goes to new email inbox and clicks approve link in email
- User is taken to the settings page with new email address.