Skip to content

Data model

DuckDB lives at DATAFORGE_HOME/dataforge.duckdb. Schema migrations are additive and execute inside a transaction. Version 1 creates tables; version 2 adds statement source content hashes; version 3 adds the compressed history recovery journal. Version 4 adds temporary recovery; version 5 adds indexed column transformation facts. Version 8 adds dbt_projects, dbt_resources, dbt_relationships, dbt_relation_bindings, dbt_evidence and dbt_project_snapshots. Logical dbt asset identity includes root/package/type/name/version; physical bindings remain context-qualified metadata. Evidence records source hashes, offsets, origins and optional JSON Pointers. Normalized snapshots retain historical source reachability. Version 9 adds durable AI request/attempt/context/link journals; version 10 adds separate opt-in ai_inspection_artifacts request/response capture. Protocol 5 file/part results reuse the run/unit tables rather than requiring another schema migration. Do not edit schema destructively or delete runtime data to resolve a migration error.

erDiagram
  workspaces ||--o{ source_files : inventories
  workspaces ||--o{ analysis_runs : analyzes
  ingestion_runs ||--o{ source_files : imports
  source_files ||--o{ statements : contains
  statements ||--o{ operations : describes
  operations ||--o{ operation_assets : reads_writes
  assets ||--o{ operation_assets : participates
  operations ||--o{ edges : produces
  assets ||--o{ column_usages : referenced_directly
  statements ||--o{ column_usages : proves
Table Responsibility
workspaces, settings Independent named contexts and JSON settings
ingestion_runs Source/import diagnostics, accepted/skipped/duplicate counters
source_files Stable path IDs, full decoded text, byte hash, blob reference, encoding, status, metadata
parse_cache Parser version + hash + path + config results; safely disposable
analysis_runs Status, duration, counts, config and comparison snapshots
history_archives Workspace-bound compressed recovery bodies, original byte size and creation time; committed atomically with history removal
assets, asset_aliases Stable canonical identities, display names, kind, temporary flags and resolution notes
statements Exact statement snippet, original line range, file ID and source version hash
operations, operation_assets Explicit transformation nodes with many-to-many input/output memberships
edges Derived input/output relationships with method, confidence, status and evidence keys
column_usages Scope-local direct column references and expression context
column_references Workspace/asset/column identity, quote-aware case rules, statement scope and derived variable version
column_derivations One target per expression, category/status, branch/position, source operation and committed analysis revision
column_dependencies Zero-to-many input columns or relation contexts with dependency roles
column_analysis Last committed transformation revision/parser version; absence means reanalysis required
diagnostics Parse failures, ambiguity and unresolved symbols with file/line
llm_profiles Provider config and environment variable names, never credentials
llm_records, prompt_versions AI provenance, validation outcomes, usage, prompt hashes and durable merged claims

IDs derive from workspace/path, normalized asset identity or operation identity. UI services filter by workspace. Original blobs may be shared by hash; workspace deletion leaves blobs intact to avoid deleting content referenced elsewhere. There are no destructive FK cascades; the materialization service owns cross-table transaction integrity.

History maintenance archives only unreferenced analysis/import records, preserving the latest completed analysis, current edge/inventory references and running analyses. Recovery JSON has a canonical SHA-256 integrity check; a compressed copy is journaled in the same DuckDB transaction as removal. Local JSON files provide an additional recovery copy. Restore inserts missing IDs transactionally without replacing current facts or existing history. Both copies are retained.

Migration4 adds temporary_recovery (workspace, file name, compressed bytes, original size, SHA256 and created/restored timestamps). Bytes commit before stale staging-file removal. Recovery journals are not metadata-transfer payloads and are deleted only with explicit workspace deletion. This table never authorizes cleanup outside its application namespace.

Column IDs include exact resolved asset/job identity and a shared quote-aware column key. Equivalent quoted and unquoted spellings share identity, while quoted case is preserved; quoted literal names such as "*" remain distinct from wildcard/rowset markers. Declared schemas retain original column_identifiers alongside unchanged name/type columns fields. Intermediate scopes and variable versions include immutable statement identity; they attach to an existing asset without adding CTE tables to the table graph. Physical columns can have multiple writer alternatives, which traversal does not combine into an assumed execution history. Constants have a derivation with no value dependencies. Original expressions and the statement content hash remain separate from display explanations. All column tables participate in workspace cleanup and full-home recovery; integrity inspection checks their asset, statement, input, derivation and analysis references. See transformation lineage.

Parser 16 refreshes grouping/selection dependencies and SQL/dbt reachable scopes. Downstream paths can contain both value and row-selection effects for one derivation; derivations remain deduplicated. Direct-usage reports expose computed usage_coverage with complete and source-free reasons; this is query metadata, not a new stored table. Unused column summaries require explicit complete coverage. Existing column tables and dependency-role vocabulary remain compatible; no schema migration is required.

AI project analysis persistence

Migration 6 adds staged project analysis without deleting existing facts:

Table Responsibility
ai_analysis_runs Workspace/run/mode, immutable manifest/configuration, stage/status/summary and compatible accepted results
ai_analysis_units Original file/hash/character bounds, context identity, checkpoint status and linked LLM record
ai_analysis_claims Minimal typed candidate payloads and accepted/rejected/unresolved decisions
analysis_fact_support Typed fact provenance/support links

Project network waits do not hold database transactions. Accepted facts and support publish with graph/column materialization after a freshness check; failure preserves the previous revision. Minimal accepted evidence is separate from opt-in full prompt/response history. Original operation evidence keys and sparse table pairs preserve same-line statements and prevent fabricated cross-pairs. See AI project analysis for modes, validation and reuse boundaries.

AI continuation snapshots (migration 7)

ai_analysis_snapshots(run_id,workspace_id,file_id,part,content_hash,payload) stores one bounded per-file header (part=0) plus operation parts. Operations reference exact spans in the immutable source blob. This replaces the aggregate ai_analysis_runs.accepted_results write limit; legacy JSON snapshots retain a fallback reader. The 16 MB per-record guard remains. Runs retain pinned request/configuration/protocol/publication identities and cumulative reservations. Unit stage checkpoints use compact host evidence/operation references; validated claims are per-claim rows. awaiting_continuation releases the active-run guard and retains the prior published graph.

Accepted claim payloads also retain compact source references with original encoding; detailed reports restore exact immutable quotes. Metadata-only reports omit payloads without reading source blobs. In-memory host operation metadata excludes duplicate fact arrays for wide projections.

Historical pre-protocol-5 tasks retained bounded unit_spec source/projection coordinates, reviewed candidate IDs and compact canonical v2 payloads. Protocol v4 expression references were resolved to original expression coordinates before legacy semantic validation. Those stored contracts remain readable, but their review/partition execution and paused-run continuation are not the current build path. New protocol 5 parts cite original file/hash/ character ranges directly and retain explicit incomplete coverage after bounded recovery.

Resumable AI analysis

Migration 9 adds ai_analysis_requests, ai_analysis_attempts, ai_context_dependencies and ai_link_checkpoints. They store request/item membership, independent dispatch outcomes/reservations, relevant source dependencies and staged link reports. They are included in cleanup, integrity and whole-home backup/restore. See AI persistence and ownership.

Historical adaptive records can contain source_focus, indexed context intervals, fragment and reviewed-component IDs, plus checked _expression_source_span offsets. Retained readers and maintenance must preserve them; they do not define current extraction or review.

Current part checkpoints use context_hash='extraction5', exact original source identity and a serialized PartExtraction. Finalized files use unit_id='file5:'+file_id with a FileExtraction. Both reuse ai_analysis_units, with the existing 16 MiB JSON record bound. Original parts survive completion/consolidation and failed refinement. Run summaries pin protocol/source/settings/model/allocation and hold recovery/split membership. Request and attempt journals retain batch membership and every reservation/outcome across resume. After bounded failure, saved partial/unresolved items remain distinct from completed work; available validated details can publish atomically with incomplete coverage.

Optional ai_inspection_artifacts captures are separate from validated checkpoints: 4 MiB per artifact, 64 MiB per run and at most seven days (or shorter workspace retention). Credential redaction on retained copies does not reconstruct missing payloads or alter original source evidence. See request inspection.