Schema
CREATE TABLE chat_sessions (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL DEFAULT 'New chat',
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
archived INTEGER NOT NULL DEFAULT 0
);
Semantics
idis a random hex string, not a sequence. It is a lookup key, not a capability: every route resolves it throughGetChatSession(id, userID), so a correct id in the wrong session is a 404.titleis derived from the first prompt and never regenerated — a title that rewrites itself is worse than a boring one.archivedhides a thread from the rail without deleting it. Archiving is per-user by construction, because the row belongs to one user.updated_atorders the rail and drives the "2m ago" label; a finished run touches it.
Invariants
- A thread cannot change owner: no code path writes
user_idafter insert. - Deleting a user removes their threads and, through the thread, their messages.
Rendered from nx-master/data-model/chat_sessions.md · OKF bundle · regenerate with npm run render