Database Setup
Discord Forum API supports multiple database backends. Choose based on your deployment needs.
Database Options
| Database | Best For | Features |
|---|---|---|
| SQLite | Development, small deployments | Zero config, file-based |
| Turso | Production, edge deployments | Multi-region, edge-compatible |
| PostgreSQL | High-scale deployments | Coming soon |
SQLite (Default)
SQLite is the default database - perfect for development and small to medium deployments.
Configuration
No configuration needed! The database file is created automatically at ./data/discord-forum.db.
To customize the path:
DATABASE_TYPE=sqliteDATABASE_PATH=./data/my-custom-name.dbInitialize Schema
Push the schema to create tables:
pnpm db:pushOr use migrations for production:
# Generate migration filespnpm db:generate
# Run migrationspnpm db:migrateSQLite Pros & Cons
Advantages:
- Zero configuration
- No external dependencies
- Fast for read-heavy workloads
- Easy to backup (just copy the file)
Limitations:
- Single writer at a time
- Not suitable for multi-instance deployments
- No built-in replication
Turso
Turso is a SQLite-compatible database optimized for edge deployments.
Why Turso?
- Edge-compatible: Deploy data close to users globally
- Free tier: 500 databases, 9GB storage
- Serverless: No servers to manage
- SQLite compatible: Same queries, zero migration needed
Setup
-
Install Turso CLI
Terminal window # macOS/Linuxcurl -sSfL https://get.tur.so/install.sh | bash# Windows (WSL)curl -sSfL https://get.tur.so/install.sh | bash -
Sign up and authenticate
Terminal window turso auth signup# orturso auth login -
Create a database
Terminal window turso db create discord-forum-api -
Get your database URL
Terminal window turso db show discord-forum-api --url# Output: libsql://discord-forum-api-username.turso.io -
Create an auth token
Terminal window turso db tokens create discord-forum-api# Output: eyJhbGci... -
Update
.envDATABASE_TYPE=tursoTURSO_DATABASE_URL=libsql://discord-forum-api-username.turso.ioTURSO_AUTH_TOKEN=eyJhbGci... -
Push schema
Terminal window pnpm db:push
Turso CLI Commands
| Command | Description |
|---|---|
turso db list | List all databases |
turso db show <name> | Show database details |
turso db shell <name> | Interactive SQL shell |
turso db tokens create <name> | Create auth token |
turso db destroy <name> | Delete database |
Turso Pricing
| Tier | Price | Includes |
|---|---|---|
| Starter | Free | 500 DBs, 9GB storage, 1B reads/month |
| Scaler | $29/mo | Unlimited DBs, 24GB storage, higher limits |
| Enterprise | Custom | SLA, dedicated support |
Database Management
Drizzle Studio
Open a visual database browser:
pnpm db:studioThis opens a web interface where you can:
- Browse tables
- View and edit data
- Run SQL queries
- Export data
Schema Changes
When you modify the schema:
Push changes directly (fast, may lose data):
pnpm db:pushUse migrations (safe, preserves data):
# Generate migrationpnpm db:generate
# Review the generated SQL in drizzle/
# Apply migrationpnpm db:migrateBackup & Restore
SQLite
# Backupcp ./data/discord-forum.db ./data/discord-forum.db.backup
# Restorecp ./data/discord-forum.db.backup ./data/discord-forum.dbTurso
Turso handles backups automatically. For manual exports:
# Export to SQLturso db shell discord-forum-api ".dump" > backup.sql
# Restore (create new db and import)turso db create discord-forum-api-restoredturso db shell discord-forum-api-restored < backup.sqlSchema Overview
The database schema includes these main tables:
| Table | Purpose |
|---|---|
servers | Discord server metadata |
channels | Forum channel information |
threads | Forum threads |
messages | Thread messages |
users | Discord user profiles |
reactions | Message reactions |
tags | Thread tags |
Explore the full schema in packages/db/src/schema.ts.
Troubleshooting
”Database is locked”
SQLite can lock if multiple processes access it:
- Ensure only one bot instance is running
- Check for zombie processes:
ps aux | grep node - Increase busy timeout (if custom client)
“Table does not exist”
Schema wasn’t pushed:
pnpm db:pushTurso connection errors
- Verify
TURSO_DATABASE_URLformat:libsql://... - Check token hasn’t expired:
turso db tokens create <name> - Ensure network allows outbound HTTPS
Slow queries
- Check indexes exist (schema includes them by default)
- Use
EXPLAIN QUERY PLANin Drizzle Studio - Consider pagination for large result sets