DB Schema
Logs
Three models work together for log ingestion and archival.
LogEntry
Individual log entries stored in MongoDB. Archived to S3 in batches when threshold is reached.
| Field | Type | Description |
|---|---|---|
id | ObjectId | Primary key |
episodeId | String | Parent episode |
timestamp | DateTime | When log was created |
level | String | "info" | "warn" | "error" | "debug" | "fatal" |
message | String | Log message |
metadata | Json? | Arbitrary metadata |
sequenceNumber | BigInt | Auto-incrementing per episode (0, 1, 2, ...) |
createdAt | DateTime | Created timestamp |
Indexes: [episodeId, sequenceNumber], [episodeId, timestamp], [episodeId, level], [episodeId, createdAt]
LogChunk
Archived log chunks in S3. Each chunk contains up to 50k logs compressed as JSONL.gz.
| Field | Type | Description |
|---|---|---|
id | ObjectId | Primary key |
episodeId | String | Parent episode |
chunkNumber | Int | Sequential chunk number (0, 1, 2, ...) |
startSequence | BigInt | First log sequence number |
endSequence | BigInt | Last log sequence number |
startTime | DateTime | First log timestamp |
endTime | DateTime | Last log timestamp |
logCount | Int | Number of logs in chunk |
src | String | S3 key |
sizeBytes | BigInt | Compressed size |
createdAt | DateTime | Created timestamp |
lastAccessed | DateTime | Last access timestamp |
Unique: [episodeId, chunkNumber]
Indexes: episodeId, [startTime, endTime]
LogMetadata
Aggregated statistics and archival state per episode.
| Field | Type | Description |
|---|---|---|
id | ObjectId | Primary key |
episodeId | String (unique) | Parent episode |
totalLogs | BigInt | Total logs ever (default: 0) |
currentLogs | BigInt | Logs in MongoDB, not yet archived (default: 0) |
archivedLogs | BigInt | Logs archived to S3 (default: 0) |
totalChunks | Int | Number of S3 chunks (default: 0) |
nextSequenceNumber | BigInt | Next sequence to assign (default: 0) |
firstLogAt | DateTime? | Earliest log timestamp |
lastLogAt | DateTime? | Latest log timestamp |
currentMongoBytes | BigInt | Size of current logs in MongoDB (default: 0) |
archivedS3Bytes | BigInt | Size of archived chunks (default: 0) |
levelCounts | Json? | e.g. { "info": 1000000, "warn": 50000 } |
archiveThreshold | Int | Archive when currentLogs reaches this (default: 50000) |
chunkSize | Int | Logs per chunk (default: 50000) |
isArchiving | Boolean | Lock flag for concurrent archival (default: false) |
lastArchivedAt | DateTime? | Last archival timestamp |
updatedAt | DateTime | Last updated |
Indexes: currentLogs