D
DreamLake

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.

FieldTypeDescription
idObjectIdPrimary key
episodeIdStringParent episode
timestampDateTimeWhen log was created
levelString"info" | "warn" | "error" | "debug" | "fatal"
messageStringLog message
metadataJson?Arbitrary metadata
sequenceNumberBigIntAuto-incrementing per episode (0, 1, 2, ...)
createdAtDateTimeCreated 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.

FieldTypeDescription
idObjectIdPrimary key
episodeIdStringParent episode
chunkNumberIntSequential chunk number (0, 1, 2, ...)
startSequenceBigIntFirst log sequence number
endSequenceBigIntLast log sequence number
startTimeDateTimeFirst log timestamp
endTimeDateTimeLast log timestamp
logCountIntNumber of logs in chunk
srcStringS3 key
sizeBytesBigIntCompressed size
createdAtDateTimeCreated timestamp
lastAccessedDateTimeLast access timestamp

Unique: [episodeId, chunkNumber]

Indexes: episodeId, [startTime, endTime]

LogMetadata

Aggregated statistics and archival state per episode.

FieldTypeDescription
idObjectIdPrimary key
episodeIdString (unique)Parent episode
totalLogsBigIntTotal logs ever (default: 0)
currentLogsBigIntLogs in MongoDB, not yet archived (default: 0)
archivedLogsBigIntLogs archived to S3 (default: 0)
totalChunksIntNumber of S3 chunks (default: 0)
nextSequenceNumberBigIntNext sequence to assign (default: 0)
firstLogAtDateTime?Earliest log timestamp
lastLogAtDateTime?Latest log timestamp
currentMongoBytesBigIntSize of current logs in MongoDB (default: 0)
archivedS3BytesBigIntSize of archived chunks (default: 0)
levelCountsJson?e.g. { "info": 1000000, "warn": 50000 }
archiveThresholdIntArchive when currentLogs reaches this (default: 50000)
chunkSizeIntLogs per chunk (default: 50000)
isArchivingBooleanLock flag for concurrent archival (default: false)
lastArchivedAtDateTime?Last archival timestamp
updatedAtDateTimeLast updated

Indexes: currentLogs