Database Schema
Mellow's PostgreSQL schema.
Database schema
Mellow uses PostgreSQL. The schema is defined by versioned SQL migrations in
internal/db/migrations (golang-migrate), embedded in the binary and applied on startup.
Queries are generated from internal/db/queries by sqlc; there is no ORM.
Identifiers are quoted and mixed-case ("User", "MoodCheckIn", "createdAt") because the
schema is a faithful reproduction of Mellow's earlier Prisma schema, so an existing production
database keeps working unchanged.
Tables
| Table | Purpose |
|---|---|
Mellow | Single-row AI configuration (model, prompt, temperature, maxTokens, feature flags, owners). |
User | One row per Discord user Mellow has seen (id is the Discord ID). Includes Mellow-level ban fields and role. |
Guild | One row per server. Feature toggles, channel IDs, moderator role, language, Mellow-level ban fields. |
UserPreferences | Per-user settings: checkInInterval (minutes, default 720), reminder settings, aiPersonality, timezone, and the disableContextLogging / disableCrisisDetection / disableCrisisSupportDMs toggles. |
ConversationHistory | Stored messages for AI context (content encrypted). Threaded via parentId, typed via contextType, optional metadata JSONB. |
MoodCheckIn | Check-ins: mood, intensity, activity, note (mood/activity/note encrypted), nextCheckIn. |
CopingToolUsage | One row per coping tool use (toolName, usedAt). |
FavoriteCopingTool | A user's toolbox entries. |
CopingPlan | A user's personal coping plan (plan encrypted). |
JournalEntry | Journal entries (content encrypted). |
GratitudeEntry | Gratitude entries (item encrypted). |
GhostLetter | Ghost letters (content encrypted). |
CrisisEvent | Crisis screening events (details encrypted, escalated flag). |
Feedback / FeedbackReply | /feedback submissions and staff replies (message encrypted). Approval, public, and featured flags drive the testimonials API. |
Report / ReportReply | /report submissions and staff replies (message encrypted), with a status. |
SystemLog | Internal operational log entries (gateway, guild, command, crisis, system, startup, shutdown). |
ModAction | Legacy table retained for database compatibility. The Go bot does not write to it. |
Enums
Role-OWNER,ADMIN,MOD,SUPPORT,SYSTEM,USER. Mellow's internal role for command gating; unrelated to Discord roles.
Legacy fields
Some columns exist only for compatibility with the earlier schema and are unused by the Go bot,
including Mellow.presencePenalty / Mellow.frequencyPenalty (no Anthropic equivalent) and
Guild.autoModEnabled / Guild.autoModLevel / Guild.systemRoleId (Mellow has no
auto-moderation or auto-role features).
Encrypted fields
See
for the full list and the encryption scheme. Non-sensitive columns are stored in the clear so the app can query them.Source of truth
The migration files in internal/db/migrations/0001_baseline.up.sql (and any later migrations)
are authoritative. This page is a summary.