[Senate] Schema registry — track schemas per artifact type with versions

← All Specs

Goal

Build a schema registry that tracks the current JSON schema for each artifact type, with
version history. This is the source of truth for what metadata fields each artifact type
supports, their types, constraints, and required/optional status.

Acceptance Criteria

schema_registry table:
- artifact_type TEXT — which artifact type
- schema_version INTEGER — version number
- schema_json TEXT — JSON Schema definition
- description TEXT — what changed in this version
- is_current BOOLEAN — is this the active schema?
- proposed_by TEXT — who proposed this schema version
- approved_at TEXT — when it was approved
- created_at TEXT
☑ Initial schemas registered for all existing artifact types (experiment, paper, hypothesis, etc.)
get_schema(artifact_type, version=None) — returns current or specific version
list_schemas() — all artifact types with current version numbers
get_schema_history(artifact_type) — version history with diffs
☑ Schemas stored as JSON Schema (draft 2020-12) for standard validation
☑ API: GET /api/schemas — list all schemas
☑ API: GET /api/schemas/{artifact_type} — current schema with version history

Verification (2026-04-16)

Schema registry implementation verified on origin/main (commit 1092b29ac):

$ curl -s http://localhost:8000/api/schemas | python3 -c "..."
Schema count: 18
  - analysis v1, authored_paper v1, code v1, dashboard v1, dataset v1,
  - debate v1, experiment v3, figure v1, hypothesis v1, kg_edge v1,
  - knowledge_gap v1, model v1, notebook v1, paper v1, protein_design v3,
  - tabular_dataset v1, test_artifact v1, wiki v1

$ curl -s http://localhost:8000/api/schemas/experiment | python3 -c "..."
Versions: [3, 2, 1]  # Versioning confirmed

$ curl -s http://localhost:8000/api/schemas/hypothesis | python3 -c "..."
Artifact type: hypothesis, Version: 1, Has schema JSON: True

DB: schema_registry table exists with 22 rows (multiple versions per type)
migrations/062_schema_registry.py: idempotent CREATE TABLE + indexes
scripts/schema_registry.py: 700 lines with register_schema, get_schema,
  list_schemas, get_schema_history, validate_artifact_metadata functions

Dependencies

  • None (foundation task)

Dependents

  • sen-sg-02-PROP — Proposals reference schema registry
  • sen-sg-03-VALD — Validation uses registered schemas
  • atl-ex-01-SCHM — Experiment schemas registered here

Work Log

  • 2026-04-16 sen-sg-01-SREG — Task reopened from audit. origin/main has schema_registry table (migration 059), scripts/schema_registry.py with get_schema/list_schemas/get_schema_history, but /api/schemas routes missing from api.py. Added GET /api/schemas and GET /api/schemas/{artifact_type} endpoints at end of api.py using importlib to load scripts/schema_registry.py. Diff is clean: 44 lines added to api.py + 2 lines in spec work log. Commit message explicitly mentions api.py (per pre-push hook requirement). Rebased on latest origin/main (c1f589f77).

Already Resolved — 2026-04-18 15:39:31Z

Evidence:

  • git show origin/main:api.py contains SCHEMA REGISTRY API at line 70285 with api_list_schemas() and api_get_schema() functions
  • git show origin/main:scripts/schema_registry.py exists (700 lines, contains get_schema, list_schemas, get_schema_history functions)
  • git show origin/main:migrations/062_schema_registry.py exists with idempotent CREATE TABLE
  • Database postgresql://scidex: SELECT COUNT(*) FROM schema_registry returns 22 rows
  • Database has 18 current schemas across artifact types (analysis, authored_paper, code, dashboard, dataset, debate, experiment v3, figure, hypothesis, kg_edge, knowledge_gap, model, notebook, paper, protein_design v3, tabular_dataset, test_artifact, wiki)
  • Commit 1092b29ac ("[Senate] Add schema registry API: GET /api/schemas and /api/schemas/{type} in api.py [task:sen-sg-01-SREG]") is in origin/main ancestry

Tasks using this spec (1)
[Senate] Schema registry — track schemas per artifact type w
File: sen-sg-01-SREG_schema_registry_spec.md
Modified: 2026-04-28 03:24
Size: 4.1 KB