Supabase Setup
1. Create a Supabase Project
- Go to Supabase and sign up or log in
- Click “New Project”
-
Fill in your project details:
- Name: Your project name (e.g., “uxie-production”)
- Database Password: Generate a strong password
- Region: Choose closest to your users
- Pricing Plan: Start with the free tier
- Wait for your database to be provisioned (takes ~2 minutes)
2. Get Your Connection String
- In your Supabase project dashboard, go to Settings > Database
- Find the Connection string section
- Select URI format
- Copy the connection string
- Replace
[YOUR-PASSWORD]with your actual database password
The connection string should include
?pgbouncer=true if you’re using connection pooling. For serverless deployments, this is recommended.Prisma Configuration
Database Provider
The Prisma schema is configured to use PostgreSQL:Database Schema
Uxie’s database schema includes the following main models:User & Authentication Models
User & Authentication Models
User Model
- Stores user profile information
- Supports three plan tiers:
FREE,FREE_PLUS,PRO - Tracks creation date and relationships to other entities
- Manages OAuth provider accounts (Google)
- Stores access tokens, refresh tokens, and session data
- Links to User via
userId
Document Management Models
Document Management Models
Document Model
- Stores PDF documents with metadata
- Tracks vectorization status (
isVectorised) - Supports both uploaded and URL-based documents
- Includes page count, cover image, and summary
- Manages document sharing permissions
- Three roles:
EDITOR,VIEWER,OWNER
- Stores text and image highlights
- Includes bounding rectangles and coordinates
- Links to specific pages
Chat & Messaging Models
Chat & Messaging Models
Message Model
- Stores chat messages for document discussions
- Supports JSON-formatted message parts
- Links to both user and document
- Cascade deletes when document is removed
Flashcard Models
Flashcard Models
Flashcard Model
- Stores AI-generated flashcards from documents
- Includes question and answer pairs
- Tracks user attempts at flashcards
- Records user responses and correctness
- Provides additional context in
moreInfo
Feedback Model
Feedback Model
Feedback Model
- Collects user feedback
- Optional contact email for follow-up
- Categorized by type
Prisma Migrations
Initial Setup
- Install Prisma CLI:
- Generate Prisma Client:
- Run migrations:
Development Workflow
-
Make schema changes in
prisma/schema.prisma - Create migration:
- Apply to production:
Useful Commands
Open Prisma Studio to view and edit your database in a GUI
Push schema changes directly to database without creating migration files (useful for prototyping)
Reset database and apply all migrations from scratch
Connection String Format
The PostgreSQL connection string follows this format:schema=public- PostgreSQL schema to usepgbouncer=true- Use connection poolingconnection_limit=1- Limit concurrent connections (recommended for serverless)
Troubleshooting
Connection timeout errors
Connection timeout errors
If you’re getting connection timeouts:
- Check your database is running in Supabase dashboard
- Verify your IP is allowed (Supabase allows all IPs by default)
- Ensure connection string includes correct password
- Try adding
?connect_timeout=10to connection string
Too many connections
Too many connections
If you’re hitting connection limits:
- Enable connection pooling:
?pgbouncer=true - Set connection limit:
?connection_limit=1 - Close unused Prisma Client instances
- Use Prisma’s recommended connection pattern:
Schema out of sync
Schema out of sync
If Prisma Client is out of sync with database:
- Regenerate Prisma Client:
npx prisma generate - Pull current database schema:
npx prisma db pull - Create new migration:
npx prisma migrate dev
