PostgreSQL Setup
Configure PostgreSQL for persistent storage in production deployments.
PostgreSQL Setup
By default, CodeSpar uses FileStorage (JSON files on disk). For production deployments, switch to PostgreSQL for durability, concurrent access, and data that survives container restarts.
When to Use PostgreSQL
- Railway/Heroku/Fly.io — ephemeral filesystems lose data on redeploy
- Multi-instance — FileStorage doesn't support concurrent writes
- Production — you need reliable, queryable storage
Quick Start
1. Set DATABASE_URL
That's it. When DATABASE_URL is set, CodeSpar automatically uses PostgreSQL instead of FileStorage.
2. Run Migrations
3. Verify
Schema
CodeSpar creates 8 tables:
| Table | Purpose |
|---|---|
agent_memory | Key-value memory per agent |
project_configs | Linked repository configurations |
projects | Project registry |
audit_log | Immutable audit trail with hash chain |
subscribers | Newsletter subscribers |
slack_installations | Slack OAuth installations |
agent_states | Persisted agent status and autonomy level |
channel_configs | Integration tokens (Sentry, Vercel, Railway, etc.) |
Multi-Tenant
Each organization's data is stored in the same database, isolated by queries. The orgId field scopes all operations.
Drizzle ORM
CodeSpar uses Drizzle ORM for type-safe database access. The schema is defined in packages/core/src/storage/schema.ts.
To modify the schema:
- Edit
schema.ts - Run
npm run db:generateto create a migration - Run
npm run db:migrateto apply - Commit the migration file
Fallback Behavior
If DATABASE_URL is not set, CodeSpar falls back to FileStorage automatically. This makes local development simple — no database needed.