prisma/schema.prisma:1 and managed through migrations.
Prerequisites
You’ll need a PostgreSQL 12+ database. Recommended providers:- Prisma Postgres - Managed Postgres with connection pooling
- Neon - Serverless Postgres with branching
- Supabase - Open-source Firebase alternative
- Railway - Simple Postgres provisioning
Quick Start
Deploy migrations
Run existing migrations to create tables:This executes the migration defined in
prisma/migrations/20260222040408_init/migration.sql:1.Generate Prisma Client
Generate the type-safe database client:
This runs automatically via the
postinstall script in package.json:9 when you run npm install.Seed system voices
Populate the database with 20 pre-built voices:Defined in
prisma.config.ts:10. See Voice Seeding below.Schema Overview
The Prisma schema defines two main models with PostgreSQL-specific features.Models
Voice
Voice
Stores voice metadata for both system and custom voices.Key fields:
prisma/schema.prisma
variant-SYSTEM(shared) orCUSTOM(organization-specific)orgId-nullfor system voices, Clerk org ID for custom voicesr2ObjectKey- Path to reference audio in R2 (e.g.,voices/system/clxyz123)category- One of 12 categories (see Voice Categories)
prisma/schema.prisma:36.Generation
Generation
Stores TTS generation history with parameters and output references.Key fields:
prisma/schema.prisma
orgId- Required for multi-tenant data isolationvoiceId- Reference to Voice (nullable, set to null if voice is deleted)voiceName- Preserved even if voice is deletedr2ObjectKey- Path to generated WAV file
prisma/schema.prisma:57.Enums
prisma/schema.prisma:16 and prisma/schema.prisma:21.
Database Configuration
Connection Setup
Prisma connects using the@prisma/adapter-pg PostgreSQL adapter for optimal Next.js compatibility:
src/lib/db.ts
src/lib/db.ts:1.
Prisma Configuration
prisma.config.ts
seed- Runsscripts/seed-system-voices.ts:1when executingnpx prisma db seed- Custom output directory:
src/generated/prisma(defined inprisma/schema.prisma:9)
Migrations
Initial Migration
The project includes one migration that creates all tables:prisma/migrations/20260222040408_init/migration.sql
Running Migrations
- Deploy (Recommended)
- Dev
- Create New
Apply migrations without prompts (ideal for CI/CD):
Voice Seeding
The seed script populates the database with 20 system voices and uploads their audio files to R2.Seed Process
scripts/seed-system-voices.ts
scripts/seed-system-voices.ts:54.
System Voices
All 20 system voices included:View All Voices
View All Voices
| Name | Category | Language | Description |
|---|---|---|---|
| Aaron | Audiobook | en-US | Soothing and calm |
| Abigail | Conversational | en-GB | Friendly and warm |
| Anaya | Customer Service | en-IN | Polite and professional |
| Andy | General | en-US | Versatile and clear |
| Archer | Narrative | en-US | Laid-back storytelling |
| Brian | Customer Service | en-US | Professional and helpful |
| Chloe | Corporate | en-AU | Bright and bubbly |
| Dylan | General | en-US | Thoughtful and intimate |
| Emmanuel | Characters | en-US | Quirky and distinctive |
| Ethan | Voiceover | en-US | Polished and warm |
| Evelyn | Conversational | en-US | Southern charm |
| Gavin | Meditation | en-US | Calm and reassuring |
| Gordon | Motivational | en-US | Warm and encouraging |
| Ivan | Characters | ru-RU | Deep and cinematic |
| Laura | Conversational | en-US | Authentic Midwestern |
| Lucy | Customer Service | en-US | Direct and composed |
| Madison | Podcast | en-US | Energetic and chatty |
| Marisol | Advertising | en-US | Confident and persuasive |
| Meera | Customer Service | en-IN | Friendly and helpful |
| Walter | Narrative | en-US | Old and raspy, wise |
Running the Seed
- Reads 20 WAV files from
scripts/system-voices/ - Uploads each to R2 at
voices/system/{voiceId} - Creates Voice records with metadata from
scripts/seed-system-voices.ts:54 - Skips existing voices (idempotent)
Voice WAV files originate from Modal’s voice sample pack.
Prisma Commands
Essential Commands
Development Workflow
Multi-Tenancy
Resonance uses Clerk Organizations for multi-tenancy with database-level isolation.Data Isolation
System voices (variant: SYSTEM):
orgIdisnull- Visible to all organizations
- Read-only for users
variant: CUSTOM):
orgIdmatches Clerk organization ID- Only visible within the organization
- Full CRUD access
- Always scoped to
orgId - Never shared across organizations
Example Query
src/trpc/routers/.
Connection Pooling
For serverless deployments (Vercel, Railway), use connection pooling:Prisma Postgres
Automatically includes connection pooling - no configuration needed.Other Providers
Use Prisma Accelerate or a direct pooler:Troubleshooting
Migration errors
Generated client not found
Seed fails with R2 error
Ensure R2 environment variables are set before running seed:Related Documentation
Environment Variables
Required env vars for database connection
Cloudflare R2
Audio file storage for voices