1-- sqlfluff:dialect:sqlite
2CREATE TABLE IF NOT EXISTS sessions (
3 id TEXT PRIMARY KEY,
4 title TEXT NOT NULL,
5 message_count INTEGER NOT NULL DEFAULT 0 CHECK (message_count >= 0),
6 tokens INTEGER NOT NULL DEFAULT 0 CHECK (tokens >= 0),
7 cost REAL NOT NULL DEFAULT 0.0 CHECK (cost >= 0.0),
8 updated_at INTEGER NOT NULL, -- Unix timestamp in milliseconds
9 created_at INTEGER NOT NULL -- Unix timestamp in milliseconds
10);
11
12CREATE TRIGGER IF NOT EXISTS update_sessions_updated_at
13AFTER UPDATE ON sessions
14BEGIN
15UPDATE sessions SET updated_at = strftime('%s', 'now')
16WHERE id = new.id;
17END;