Database Overview
Repolyze’s database stores:User Authentication
NextAuth.js user accounts, sessions, and OAuth connections
Subscriptions
Polar.sh subscription data and plan information
Rate Limiting
IP-based tracking for analysis request limits
Audit Logs
Repository analysis request history
Prerequisites
Before you begin, ensure you have:- PostgreSQL 12 or higher installed
- Database user with CREATE DATABASE privileges
- Environment variables configured (see Environment Variables)
PostgreSQL Installation
- macOS
- Ubuntu/Debian
- Windows
- Docker
Database Setup
Create Database
Connect to PostgreSQL and create a database for Repolyze:Then run these SQL commands:
If using Docker, the database is created automatically with
-e POSTGRES_DB=repolyzeConfigure Database URL
Add the database connection string to your URL Format:Common configurations:
.env.local file:Generate Prisma Client
Generate the Prisma client from the schema:This creates TypeScript types and the Prisma client in
lib/generated/prisma/The Prisma client is automatically generated during
pnpm install via the postinstall script.Run Database Migrations
Apply the database schema to your PostgreSQL database:This will:
- Create all tables defined in
prisma/schema.prisma - Generate migration files in
prisma/migrations/ - Regenerate the Prisma client
Database Schema
Repolyze’s database schema is defined inprisma/schema.prisma:
User Model
Stores user account information and subscription data:Account Model
Stores OAuth provider connections (GitHub, Google):Session Model
Manages user session tokens:AnalysisRequest Model
Tracks repository analysis requests for rate limiting:Prisma Commands
Useful Prisma commands for database management:Prisma Studio
Prisma Studio is a visual database browser:http://localhost:5555 where you can:
- Browse and edit database records
- Filter and search data
- Create, update, and delete records
- View relationships between models
Connection Pooling
For production deployments, use connection pooling with Prisma Accelerate or pgBouncer:Using Prisma with pg Adapter
Repolyze uses@prisma/adapter-pg for better connection handling:
This is already configured in Repolyze’s codebase. The
@prisma/adapter-pg and pg packages are installed.Environment-Specific Configuration
Development
Use a local PostgreSQL instance:Production
Use a managed PostgreSQL service with SSL:Troubleshooting
Connection refused error
Connection refused error
If you see
Error: connect ECONNREFUSED 127.0.0.1:5432:-
Verify PostgreSQL is running:
-
Check if PostgreSQL is listening on the correct port:
-
Verify
DATABASE_URLin.env.localis correct
Authentication failed error
Authentication failed error
If you see
Error: password authentication failed:- Verify username and password in
DATABASE_URL - Check PostgreSQL user permissions:
- Reset user password if needed:
Database does not exist
Database does not exist
If you see
Error: database "repolyze" does not exist:Migration errors
Migration errors
If migrations fail:
- Check the error message carefully
- Verify database connection is working
- Try resetting migrations (WARNING: deletes all data):
- Manually apply migrations:
Prisma client not found
Prisma client not found
If you see
Cannot find module '@prisma/client':SSL/TLS connection errors
SSL/TLS connection errors
For production databases requiring SSL:
Best Practices
Use Separate Databases
Use different databases for development, staging, and production
Regular Backups
Set up automated backups for production databases
Monitor Performance
Track query performance and optimize slow queries
Connection Limits
Configure appropriate connection pool limits
Schema Changes
When modifying the Prisma schema:- Edit
prisma/schema.prisma - Create a migration:
- Review the generated SQL in
prisma/migrations/ - Test the migration in development
- Apply to production:
Next Steps
Installation
Complete the installation process
Environment Variables
Configure API keys and settings
API Reference
Learn about the API endpoints
Contributing
Contribute to Repolyze