What Database is Used For
Gorkie stores:- Sandbox Sessions: E2B sandbox lifecycle and state (
sandbox_sessionstable) - Scheduled Tasks: Cron-based recurring tasks (
scheduled_taskstable)
Database Schema Overview
Gorkie’s schema is defined inserver/db/schema.ts:
Sandbox Sessions Table
Tracks E2B sandbox instances and their lifecycle:| Column | Type | Description |
|---|---|---|
thread_id | text (PK) | Slack thread ID associated with sandbox |
sandbox_id | text | E2B sandbox identifier |
session_id | text | Session identifier |
status | text | Current status (creating, active, paused, destroyed) |
paused_at | timestamp | When sandbox was paused |
resumed_at | timestamp | When sandbox was resumed |
destroyed_at | timestamp | When sandbox was destroyed |
created_at | timestamp | Record creation time |
updated_at | timestamp | Last update time |
sandbox_sessions_status_idxonstatussandbox_sessions_paused_idxonpaused_atsandbox_sessions_updated_idxonupdated_at
Scheduled Tasks Table
Stores recurring tasks configured via Slack:| Column | Type | Description |
|---|---|---|
id | text (PK) | Unique task identifier |
creator_user_id | text | Slack user ID who created the task |
destination_type | text | Where to send results (channel, dm, thread) |
destination_id | text | Channel/user ID for results |
thread_ts | text | Thread timestamp if posting to thread |
prompt | text | AI prompt to execute |
cron_expression | text | Cron schedule expression |
timezone | text | Timezone for cron schedule |
enabled | boolean | Whether task is active |
next_run_at | timestamp | Next scheduled execution |
running_at | timestamp | Currently running timestamp |
last_run_at | timestamp | Last execution time |
last_status | text | Result of last run |
last_error | text | Error from last run if failed |
created_at | timestamp | Record creation time |
updated_at | timestamp | Last update time |
scheduled_tasks_due_idxonenabled, next_run_atscheduled_tasks_running_idxonrunning_atscheduled_tasks_creator_idxoncreator_user_id
Local Development
Option 1: Neon (Recommended)
Neon provides a generous free tier with serverless Postgres:Create a Neon account
Sign up at https://neon.tech
Create a project
- Click “Create a project”
- Choose a name and region
- Note the connection string provided
- Free tier: 0.5 GB storage, 10 GB data transfer
- Serverless (auto-scaling and auto-pause)
- No local setup required
- Branching for development
Option 2: Docker Postgres
Run Postgres locally with Docker:Option 3: Native Postgres
Install Postgres locally:macOS (Homebrew)
Ubuntu/Debian
Verify Local Setup
Production Setup
Neon (Recommended)
Neon is ideal for production Postgres:Upgrade plan if needed
Free tier supports most small to medium deployments. Upgrade for:
- More storage (>512 MB)
- Higher compute resources
- Additional branches
Enable connection pooling
Neon includes connection pooling by default. Use the pooled connection string:Note the
-pooler in the hostname.Supabase
Supabase provides Postgres with additional features:Create a project
Sign up at https://supabase.com and create a project.
- Free tier: 500 MB storage, 2 GB data transfer
- Automatic backups
- Built-in connection pooling
- Additional features (Auth, Storage, Realtime)
Railway
If deploying on Railway:Render
If deploying on Render:Create Postgres instance
- Click “New” → “PostgreSQL”
- Choose a name and region
- Select plan (free tier available)
Link to web service
- Go to your web service settings
- Add
DATABASE_URLenvironment variable - Use the Internal Database URL
Self-Hosted
For VPS deployments, install and configure Postgres:pg_hba.conf for authentication:
Connection String Format
Basic Format
With SSL (Required for Production)
disable: No SSL (local dev only)require: Require SSL but don’t verify certificateverify-ca: Require SSL and verify CAverify-full: Require SSL and verify hostname
With Connection Pooling
Some providers offer pooled connections:Database Migrations with Drizzle
Gorkie uses Drizzle Kit for database migrations.Configuration
The Drizzle config is indrizzle.config.ts:
Available Commands
Typical Workflow
Quick Development (db:push)
For rapid iteration during development:Production Migrations
For production deployments with version control:Viewing Your Data
Drizzle Studio provides a GUI for browsing data:https://local.drizzle.studio
Querying the Database
Gorkie uses Drizzle ORM for type-safe queries.Example: Query Sandbox Sessions
Example: Query Scheduled Tasks
Backup and Recovery
Automated Backups
Most cloud providers handle backups automatically:- Neon: Automatic backups with point-in-time recovery
- Supabase: Daily backups with 7-day retention on free tier
- Railway: Automatic backups on paid plans
- Render: Daily backups with 7-day retention
Manual Backup
Backup Specific Tables
Monitoring
Check Database Size
Table Statistics
Active Connections
Troubleshooting
Connection Refused
- Check Postgres is running:
pg_isready - Verify host and port in
DATABASE_URL - Check firewall rules
Authentication Failed
- Verify username and password in
DATABASE_URL - Check
pg_hba.confauthentication method - Ensure user has correct permissions
SSL/TLS Required
- Add
?sslmode=requiretoDATABASE_URL - For Neon/Supabase, SSL is always required
Migration Conflicts
- Drop and recreate tables (dev only):
bun run db:push --force - Reset migration state
- Check for duplicate migrations
Database Connection Limit
- Use connection pooling (Neon:
-poolerhostname) - Reduce max connections in app
- Upgrade database plan
Best Practices
Always use SSL (
?sslmode=require) for production databasesEnable connection pooling for serverless/distributed deployments
Run migrations in CI/CD pipeline before deployment
Monitor database size and performance metrics
Set up automated backups and test restoration
Use environment-specific databases (dev, staging, production)
Never commit
DATABASE_URL or credentials to gitRegularly update to latest Drizzle version