Skip to content

Database tables

The Atreides database is ClickHouse. It stores control-plane metadata and operational records only; snapshots, prepared frames, and model artifacts stay in filesystem/S3-backed stores.

The schema source of truth is src/infra/persistence/clickhouse/migrations.py. just db-init applies the pending migrations and records applied versions in schema_migrations.

Current migration-created tables

These tables are created by the current ClickHouse migrations.

TableOwnerPurpose
schema_migrationsmigration runnerRecords which ClickHouse schema migrations have already been applied.
model_definitionsmodeling repositoryStores the latest persisted snapshots of ModelDefinition aggregates.
promotion_auditsmodeling repositoryStores promotion attempts and their audit payloads.
forecast_runsforecast result persistence jobStores requested forecast runs, execution status, execution reference, and canonical forecast frames.
demand_snapshotssnapshot repositoryStores snapshot materialization command state and manifest URI.
configuration_revisionsconfiguration revision repositoryStores runtime configuration revisions by tenant, scope, kind, and status.

schema_migrations

Internal migration ledger used by infra.persistence.clickhouse.migrations.

ColumnTypeMeaning
versionStringMigration version identifier.
descriptionStringHuman-readable migration description.
applied_atDateTime64(6, 'UTC')Time when the migration was recorded. Defaults to now64(6).

Engine: ReplacingMergeTree(applied_at)

Sort key: version

model_definitions

Durable write-side state for model-definition aggregates. The table keeps an opaque JSON aggregate payload plus top-level columns used for tenant and entity lookup.

ColumnTypeMeaning
idUUIDModel definition id.
organization_idUUIDTenant id. This must match the command tenant scope.
payloadStringJSON-encoded ModelDefinitionRecord.
created_atDateTime64(6, 'UTC')Timestamp written by the repository for the saved aggregate.
updated_atDateTime64(6, 'UTC')Timestamp written by the repository for the saved aggregate.
recorded_atDateTime64(6, 'UTC')ClickHouse replacement/version timestamp. Defaults to now64(6).

Engine: ReplacingMergeTree(recorded_at)

Sort key: organization_id, id

Notes:

  • payload includes model versions, strategy specs, validation policy, projection recipe, feature recipe, champion reuse policy, trained instances, serving references, and metric snapshots.
  • Reads fetch the newest row for id by recorded_at.

promotion_audits

Append-oriented audit table for model promotion attempts. The top-level columns support tenant, model, series, version, and status access. The full immutable audit detail is stored in payload.

ColumnTypeMeaning
idUUIDPromotion audit id.
organization_idUUIDTenant id.
model_definition_idUUIDPromoted model definition id.
series_keyStringCanonical serialized series identity.
target_versionUInt32Candidate model instance version targeted by promotion.
statusLowCardinality(String)Promotion audit status.
payloadStringJSON-encoded PromotionAuditRecordPayload.
created_atDateTime64(6, 'UTC')Audit creation time.
completed_atNullable(DateTime64(6, 'UTC'))Completion time for finished attempts.
recorded_atDateTime64(6, 'UTC')ClickHouse replacement/version timestamp. Defaults to now64(6).

Engine: ReplacingMergeTree(recorded_at)

Sort key: organization_id, model_definition_id, series_key, target_version, id

forecast_runs

Stores write-side forecast run results produced by the prediction job path. The table keeps queryable run identifiers and stores forecast details in payload.

ColumnTypeMeaning
idUUIDForecast run id.
organization_idUUIDTenant id.
model_definition_idUUIDModel definition used for the forecast.
model_versionUInt32Requested model version.
series_keyStringCanonical serialized series identity.
statusLowCardinality(String)Forecast run status.
payloadStringJSON payload with horizon, unit, execution reference, and canonical forecast frame columns.
requested_atDateTime64(6, 'UTC')Time the forecast was requested.
recorded_atDateTime64(6, 'UTC')ClickHouse replacement/version timestamp. Defaults to now64(6).

Engine: ReplacingMergeTree(recorded_at)

Sort key: organization_id, model_definition_id, series_key, model_version, id

Completed forecast runs require an execution_reference object in payload. It records the active model instance version, strategy key, artifact URI, resolved config hash, validation policy hash, projection recipe hash, feature recipe hash, strategy params hash, and selection policy hash used by the forecast execution.

Forecast frame payloads are produced by execute_model_forecasts, written as Parquet artifacts, and then loaded by persist_forecast_results. The final write uses Spark’s ClickHouse catalog writer against forecast_runs.

demand_snapshots

Tracks the state of snapshot materialization commands. The control plane stores the source locator and materialization state here; the canonical frame and manifest stay in the configured demand storage backend.

ColumnTypeMeaning
idUUIDSnapshot id.
organization_idUUIDTenant id.
input_pathStringOriginal input locator supplied to the command.
source_formatLowCardinality(String)Declared source format, currently csv or parquet.
statusLowCardinality(String)Snapshot materialization status.
snapshot_manifest_uriNullable(String)URI to the canonical snapshot manifest after successful materialization.
error_messageNullable(String)Failure detail for failed materializations.
created_atDateTime64(6, 'UTC')Snapshot creation time.
updated_atDateTime64(6, 'UTC')Last status update time.
completed_atNullable(DateTime64(6, 'UTC'))Completion time for terminal states.
recorded_atDateTime64(6, 'UTC')ClickHouse replacement/version timestamp. Defaults to now64(6).

Engine: ReplacingMergeTree(recorded_at)

Sort key: organization_id, id

Reads fetch the newest row for id by recorded_at.

configuration_revisions

Stores runtime configuration revisions that can be activated or deprecated by tenant, scope, and configuration kind.

ColumnTypeMeaning
idUUIDConfiguration revision id.
organization_idUUIDTenant id.
scope_typeLowCardinality(String)Runtime config scope type.
scope_keyStringRuntime config scope key.
config_kindLowCardinality(String)Kind of configuration stored in the payload.
payload_hashStringStable hash of the JSON payload.
statusLowCardinality(String)Revision status, such as active or deprecated.
created_byStringActor that created the revision.
payloadStringJSON object with the effective runtime configuration.
created_atDateTime64(6, 'UTC')Revision creation time.
activated_atNullable(DateTime64(6, 'UTC'))Activation time for active revisions.
recorded_atDateTime64(6, 'UTC')ClickHouse replacement/version timestamp. Defaults to now64(6).

Engine: ReplacingMergeTree(recorded_at)

Sort key: organization_id, scope_type, scope_key, config_kind, status, id

Reads fetch the newest active row by organization_id, scope_type, scope_key, and config_kind, ordered by recorded_at.

Adding or changing tables

When a persistence adapter adds a new table or column:

  1. Add an ordered ClickHouseMigration in src/infra/persistence/clickhouse/migrations.py.
  2. Keep table ownership in src/infra/persistence/clickhouse/* adapters; do not leak ClickHouse details into application or domain code.
  3. Update this page and any affected operation docs.
  4. Run the narrow persistence tests first, then the relevant quality gate.