Skip to content

ContextBuilderService — DDL appendix

Generated from the architecture model

This page is rendered from model/**/*.yaml by tools/docs_model during mkdocs build. Edit the YAML, not this page; hand-written design lives on the linked service, platform and plane pages.

Dialect shown: SQL Server (nvarchar, uniqueidentifier, datetimeoffset). Migrations are authored as FluentMigrator classes in the service's DatabaseModel.Migrations project; the TenantId column and the NHibernate tenant filter follow canonical ADR-0100 in SharedDb mode.

dbo.ContextSnapshots

Owner: ContextSnapshot · Retention: follows the run's retention (1 year default, D31)

CREATE TABLE [dbo].[ContextSnapshots] (
    [ContextSnapshotId] uniqueidentifier NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [ProjectId] nvarchar(64) NOT NULL,
    [RunId] uniqueidentifier NOT NULL,
    [AttemptId] uniqueidentifier NOT NULL,
    [PlanRef] nvarchar(512) NOT NULL,
    [TokenBudget] int NOT NULL,
    [TokensUsed] int NOT NULL,
    [Status] int NOT NULL,
    [IndexRevisionsJson] nvarchar(2000) NOT NULL,
    [MemoryItemsJson] nvarchar(2000) NOT NULL,
    [ContentRef] nvarchar(512) NOT NULL,
    [AssembledAt] datetimeoffset NOT NULL,
    CONSTRAINT [PK_ContextSnapshots] PRIMARY KEY ([ContextSnapshotId])
);
CREATE INDEX [IX_ContextSnapshots_Run_Attempt] ON [dbo].[ContextSnapshots] ([RunId], [AttemptId]);
Column Type Null Key Description
ContextSnapshotId uniqueidentifier no PK
TenantId nvarchar(64) no
ProjectId nvarchar(64) no
RunId uniqueidentifier no
AttemptId uniqueidentifier no
PlanRef nvarchar(512) no
TokenBudget int no
TokensUsed int no
Status int no
IndexRevisionsJson nvarchar(2000) no
MemoryItemsJson nvarchar(2000) no
ContentRef nvarchar(512) no
AssembledAt datetimeoffset no

dbo.ContextItems

Owner: ContextItem

CREATE TABLE [dbo].[ContextItems] (
    [ItemId] uniqueidentifier NOT NULL,
    [ContextSnapshotId] uniqueidentifier NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [Section] int NOT NULL,
    [SourceKind] nvarchar(16) NOT NULL,
    [Reference] nvarchar(512) NOT NULL,
    [SourceVersion] nvarchar(128) NULL,
    [TrustTier] nvarchar(24) NOT NULL,
    [Score] decimal(6,4) NOT NULL,
    [Included] bit NOT NULL,
    [DropReason] nvarchar(64) NULL,
    [Tokens] int NOT NULL,
    [Compressed] bit NOT NULL DEFAULT (0),
    CONSTRAINT [PK_ContextItems] PRIMARY KEY ([ItemId])
);
ALTER TABLE [dbo].[ContextItems] ADD CONSTRAINT [FK_ContextItems_ContextSnapshots_ContextSnapshotId] FOREIGN KEY ([ContextSnapshotId]) REFERENCES [dbo].[ContextSnapshots] ([ContextSnapshotId]);
CREATE INDEX [IX_ContextItems_Snapshot_Section] ON [dbo].[ContextItems] ([ContextSnapshotId], [Section]);
Column Type Null Key Description
ItemId uniqueidentifier no PK
ContextSnapshotId uniqueidentifier no FK → ContextSnapshots.ContextSnapshotId
TenantId nvarchar(64) no
Section int no
SourceKind nvarchar(16) no
Reference nvarchar(512) no
SourceVersion nvarchar(128) yes
TrustTier nvarchar(24) no
Score decimal(6,4) no
Included bit no
DropReason nvarchar(64) yes
Tokens int no
Compressed bit no