Prerequisites
- A Supabase account
- Basic understanding of PostgreSQL
- Access to create and manage database tables
Creating a Supabase Project
Sign up or sign in
Go to supabase.com and create an account or sign in.
Create a new project
Click New Project and provide:
- Project name: Choose a descriptive name (e.g., “highway-production”)
- Database password: Create a strong password (save this securely)
- Region: Select the closest region to your users
Getting API Keys
Once your project is ready, you’ll need two API keys:Copy the Project URL
Find your Project URL (e.g.,
https://xxxxx.supabase.co). You’ll need this for the client configuration.Get the anon key
Copy the anon (public) key. This key is safe to use in frontend applications with Row Level Security enabled.
Environment Configuration
Add your Supabase credentials to.env:
Database Tables Setup
Highway requires two main tables:verifications and calls.
Verifications Table
Stores customer verification data:Calls Table
Tracks call history and status:Table Schemas and Relationships
Verifications Schema
| Column | Type | Description |
|---|---|---|
id | SERIAL | Primary key, auto-incrementing |
created_at | TIMESTAMP | Record creation timestamp |
customer_name | TEXT | Customer’s name |
phone_number | TEXT | Customer’s phone number |
verification_data | JSONB | Flexible data storage for verification info |
status | TEXT | Verification status (pending, completed, failed) |
Calls Schema
| Column | Type | Description |
|---|---|---|
id | SERIAL | Primary key, auto-incrementing |
created_at | TIMESTAMP | Call creation timestamp |
verification | INTEGER | Foreign key to verifications table |
status | TEXT | Call status (in_progress, successful_call, etc.) |
call_sid | TEXT | Twilio call SID |
duration | INTEGER | Call duration in seconds |
recording_url | TEXT | URL to call recording |
transcription | TEXT | Call transcription text |
updated_at | TIMESTAMP | Last update timestamp |
Relationship Diagram
The
verification column in the calls table creates a one-to-many relationship, allowing multiple call attempts per verification.Row Level Security (RLS) Policies
Enable RLS to secure your data:These are basic RLS policies. In production, you should implement more granular policies based on user roles and ownership.
Client Configuration
Backend Configuration
Highway’s backend uses the Supabase client for server-side operations:routes.js
Using the Client
Creating a call record:routes.js
websocket.js
websocket.js
Frontend Configuration (Optional)
If you have a frontend dashboard, use the anon key:Frontend environment variables should be prefixed with
NEXT_PUBLIC_ (Next.js) or VITE_ (Vite) to expose them to the client.Testing Database Operations
Database Monitoring
Best Practices
Security
- Use RLS policies: Always enable Row Level Security
- Separate keys: Use
anon_keyfor frontend,service_rolefor backend only - Validate inputs: Sanitize data before inserting into the database
- Rotate keys: Regularly rotate API keys for security
Performance
- Add indexes: Index frequently queried columns
- Use select(): Only fetch columns you need
- Batch operations: Use bulk inserts when possible
- Monitor queries: Check slow queries in Supabase logs
Data Management
- Backup regularly: Enable automated backups in project settings
- Clean old data: Archive or delete old call records
- Use JSONB wisely: Store flexible data in
verification_data - Add timestamps: Track created_at and updated_at for all records
Troubleshooting
Common Issues
Connection errors- Verify your Supabase URL and API keys are correct
- Check that your project is not paused (free tier limitation)
- Ensure network allows connections to Supabase
- Check RLS policies are configured correctly
- Verify user authentication status
- Use service_role key for server-side operations that need full access
- Validate data types match table schema
- Check foreign key constraints
- Review RLS policies for INSERT/UPDATE permissions
- Add indexes on frequently queried columns
- Limit result sets with
.limit() - Use
.select('column1, column2')instead of.select('*')
Next Steps
- Configure Twilio for phone integration
- Set up OpenAI for AI processing
- Learn about Environment Variables