Skip to main content

Database Schema

The application database is PostgreSQL. Models are defined with SQLAlchemy 2.0 typed mappings on a shared Base (saas/models/base.py). This page documents the core tables. Columns are taken directly from the model files (saas/auth/models.py, saas/jobs/models.py); only the schema-significant fields are described.

Migrations are managed with Alembic (alembic upgrade head, run by the one-shot migrate service). See Migrations.

userssaas/auth/models.py

ColumnTypeNotes
idintPK, autoincrement.
emailvarchar(255)Unique, indexed.
password_hashvarchar(255)bcrypt hash.
created_attimestamptzDefaults to now (UTC).
email_verifiedboolDefaults to False.
verification_tokenvarchar(255)Nullable.
reset_tokenvarchar(255)Nullable.
reset_token_expirestimestamptzNullable.

simulation_jobssaas/jobs/models.py

The central table. One row per simulation job.

ColumnTypeNotes
idintPK, autoincrement.
user_idvarchar(255)Indexed.
seed_texttextThe seed document.
goaltextNullable prediction goal.
tiervarchar(20)Nullable; maps to a model_routing row.
credits_chargedintDead column — see below. Defaults to 0.
statusenum JobStatusDefaults to PENDING.
pipeline_stageintNullable; pipeline progress marker.
result_reporttextNullable; report markdown.
result_chat_logtextNullable; agent chat log JSON.
result_graphtextNullable; entity graph JSON.
result_structuredtextNullable; structured results payload JSON.
error_messagetextNullable; failure reason.
gpu_providervarchar(50)Nullable.
gpu_cost_usdfloatNullable.
created_attimestamptzDefaults to now (UTC).
completed_attimestamptzNullable.
pod_idvarchar(255)Nullable, indexed.
celery_task_idvarchar(255)Nullable.
workflow_idvarchar(255)Nullable, indexed; the Temporal workflow id.
workflow_run_idvarchar(255)Nullable.
retry_countintDefaults to 0.
retry_ofintNullable; id of the job this is a retry of.
provision_secondsintNullable.
pipeline_secondsintNullable.
key_insightvarchar(200)Nullable; one-line takeaway.
share_tokenvarchar(64)Nullable, unique, indexed; public share link.
last_heartbeattimestamptzNullable; liveness for the stale-job detector.
enrich_webboolDefaults to True.
enriched_seedtextNullable; the enriched seed.
enrichment_citationstextNullable.
forecast_daysintNullable; prediction horizon.
sim_data_availableboolDefaults to False; set true once artifacts land in MinIO.
live_statusJSONNullable; live progress snapshot.
resume_task_idvarchar(255)Nullable.
markets_configJSONNullable; the per-sim derived prediction markets.

JobStatus enum

DRAFT, PENDING, PROVISIONING, RUNNING, REPORTING, COMPLETED, FAILED, REFUNDED.

Dead-but-retained billing artifacts

The open-source pivot removed billing/credits, but two billing artifacts were deliberately kept to avoid invasive PostgreSQL schema surgery (notably the hassle of removing a value from an existing enum type):

  • credits_charged — retained as a dead column that always stays 0. Its default lets inserts omit it.
  • REFUNDED status — retained as a JobStatus enum value. It is no longer reached by normal job flow, but report-task idempotency still treats it as a terminal state alongside COMPLETED and FAILED.

Neither is part of any active code path that charges or refunds — there is no billing in the OSS build.

model_routingsaas/jobs/models.py

Operator-configurable map from tier to model and GPU. Single source of truth read at job creation. Tier configuration is seeded in tests via the seeded_routing fixture.

ColumnTypeNotes
idintPK, autoincrement.
sim_tiervarchar(20)Unique.
model_idvarchar(255)HF model id (e.g. Qwen/Qwen3-14B).
gpu_typevarchar(50)e.g. NVIDIA L40S.
max_roundsintDefaults to 200.
vllm_argstextNullable; extra vLLM flags.
target_agentsintDefaults to 5.

error_eventssaas/jobs/models.py

Captures unhandled errors for diagnosis (written by the error-tracking middleware and other call sites).

ColumnTypeNotes
idintPK, autoincrement.
timestamptimestamptzDefaults to now (UTC).
levelvarchar(20)Defaults to ERROR.
sourcevarchar(20)api, worker, or gpu.
messagetextError message.
tracebacktextNullable.
user_idvarchar(255)Nullable.
job_idintNullable.
request_pathvarchar(500)Nullable.