Database Schema Overview
The application uses three main database tables:Session Table
Stores Shopify OAuth session data including access tokens and shop information.BillingSchedule Table
Manages billing schedules for subscription processing with timezone and timing configuration.DunningTracker Table
Tracks failed billing attempts and dunning processes for subscription recovery.Database Provider Options
SQLite (Development Only)
The default configuration uses SQLite:- Single file-based database
- No concurrent write support
- Not suitable for production workloads
- Limited scalability
PostgreSQL (Recommended for Production)
PostgreSQL is the recommended database for production deployments.Set Database URL
Configure your PostgreSQL connection string in
.env:Include
?schema=public to specify the PostgreSQL schema. For connection pooling, see the Connection Pooling section.MySQL
MySQL is also supported for production deployments.Prisma Schema Details
The complete Prisma schema fromprisma/schema.prisma:
Database Setup Commands
Initialize Database
Run the setup script to generate Prisma Client and deploy migrations:prisma generate- Generates TypeScript types and Prisma Clientprisma migrate deploy- Runs all pending migrations
Run Migrations
Apply database migrations in production:Always run migrations before starting your application server.
Generate Prisma Client
Regenerate Prisma Client after schema changes:Create New Migration (Development)
Create a new migration after modifying the schema:View Database in Prisma Studio
Open Prisma Studio to view and edit database records:Connection Configuration
Connection String Format
Connection Pooling
For production deployments with connection pooling (e.g., PgBouncer):app/db.server.ts to use the pooled connection:
Database Hosting Options
Managed Database Services
PostgreSQL Options:- Supabase - Free tier available
- Neon - Serverless PostgreSQL
- Railway - Easy PostgreSQL setup
- AWS RDS - Enterprise-grade
- Google Cloud SQL - Managed PostgreSQL
- DigitalOcean Managed Databases
- PlanetScale - Serverless MySQL
- AWS RDS - MySQL support
- Google Cloud SQL - MySQL support
Choose a database provider in the same region as your application server to minimize latency.
Production Database Best Practices
Enable Connection Pooling
Use connection pooling to handle multiple concurrent requests efficiently:
- PgBouncer for PostgreSQL
- ProxySQL for MySQL
- Built-in pooling from managed providers
Set Up Backups
Configure automated database backups:
- Daily automated backups (minimum)
- Point-in-time recovery enabled
- Backup retention policy (30+ days recommended)
- Test backup restoration regularly
Monitor Database Performance
Implement database monitoring:
- Query performance tracking
- Connection pool metrics
- Slow query logs
- Database resource utilization
Secure Database Access
Follow security best practices:
- Use strong passwords
- Enable SSL/TLS connections
- Restrict network access (IP whitelist)
- Use environment variables for credentials
- Never commit credentials to version control
Session Storage Configuration
The app supports two session storage modes:Prisma Session Storage (Production)
Stores sessions in your database using Prisma:Memory Session Storage (Development/Testing)
Stores sessions in memory (data lost on restart):Troubleshooting
Migration Failures
If migrations fail:Connection Issues
Test database connectivity:- Incorrect connection string format
- Firewall blocking database port
- Invalid credentials
- SSL certificate issues