K12 Database (Overview)
What this section is for
Use this section when you’re:
- implementing or debugging K12 EOP workflows
- implementing or debugging K12 QRG generation/editing
- tracing a request from tool call → workflow run → stored result
This section is K12-focused by design.
For cross-cutting database topics (Core tables, agent prompt storage, etc.), see the Database tab:
/database/overview/database/agents
Where K12 data lives
K12 workflow data is stored in Azure SQL under the K12SAFETY schema.
The schema has two “table families” most commonly encountered:
-
EOP request logging & monitoring
- Optimized for auditing and operational timelines.
- Documented in
/k12/internal/database/eop.
-
QRG normalized storage
- Optimized for querying and downstream consumption.
- Documented in
/k12/internal/database/qrg.
Source of truth for table definitions
- Exhaustive schema model (DACPAC):
db/sqlproj/Mastra.Platform.K12SafetyDb/model/Tables/*
- Seed scripts and K12-specific utilities:
db/k12/seed/
Quick verification
- Verify connectivity + presence of key tables through the admin DB health tool:
POST /admin/tools/db-health-check- Operator/runtime route only. Replit/Admin UI browser flows should use
local
/admin-api/*or testing/dashboard/admin-api/*.
K12SAFETY schema architecture
The K12SAFETY schema contains two main table families:
EOP Tables (Logging & Monitoring)
log_EOP_TaskRequests- Request and response envelopelog_EOP_TaskStatus- Status timeline for monitoringlog_Jobs- Async execution statelog_EOP_TaskRequestSystemPrompts- Prompt override auditinglog_EOP_TaskRequestContext- Resolved snapshot, organization, and role context per request
See the EOP database page for the complete ER diagram and detailed documentation.
QRG Tables (Normalized Storage)
qrg_requests- Request envelope and statusqrg_generations- Generation metadataqrg_generated_items- Individual QRG itemsqrg_generation_annexes- Per-annex processing tracking (status, classification, extraction)qrg_ai_calls- Individual AI call logs (prompt, response, tokens, duration)qrg_execution_errors- Workflow-level error trackingqrg_edits- Editing resultsqrg_edit_context- Edit context snapshots (organization, role tags, QRG metadata)qrg_request_prompts- Captured promptsqrg_request_roles- Role/tag associations
See the QRG database page for the complete ER diagram and detailed documentation.
Views
vw_eop_request_traceability- Joins EOP request, status, job, and prompt datavw_qrg_full_traceability- Full QRG request-to-result traceabilityvw_qrg_input_output_trace- Annex input vs QRG output comparisonvw_qrg_ai_call_summary- AI call metrics per requestvw_qrg_annex_ai_details- Per-annex AI processing detailsvw_qrg_error_summary- Joined error analysis with request/annex contextvw_qrg_edit_traceability- QRG edit request-to-result traceability
Table summary
| Table | Purpose | Key columns |
|---|---|---|
log_EOP_TaskRequests | EOP workflow task requests and responses | RequestID, TaskName, ResponseStatus |
log_EOP_TaskStatus | EOP task status timeline | RequestID, Status, StatusMessage |
log_Jobs | General job logging for K12 workflows | request_id, job_type, status |
log_EOP_TaskRequestSystemPrompts | Prompt override auditing | RequestID, PromptHash |
log_EOP_TaskRequestContext | Resolved context (snapshot, org, roles) | RequestID, ContextResolutionStatus |
qrg_requests | Parent table for QRG generation/editing requests | RequestId, RequestType, Status |
qrg_generations | QRG generation metadata and results | RequestId (FK), AnnexCount, QrgCount |
qrg_generated_items | Individual generated QRG items | RequestId (FK), QrgName, QrgType |
qrg_generation_annexes | Per-annex processing tracking | RequestId (FK), AnnexId, ProcessingStatus |
qrg_ai_calls | Individual AI call logs | RequestId (FK), StepType, Status, TotalTokens |
qrg_execution_errors | Workflow-level error tracking | RequestId (FK), ErrorType, FailedStep |
qrg_edits | QRG editing requests and results | RequestId (FK), QrgName, Section |
qrg_edit_context | Edit context snapshots | RequestID, ContextStatus |
qrg_request_prompts | Custom prompts for QRG requests | RequestId (FK), UserPrompt, SystemPromptHash |
qrg_request_roles | User roles associated with requests | RequestId (FK), RoleLabel, RoleTagId |
Next pages
- EOP tables:
/k12/internal/database/eop - QRG tables:
/k12/internal/database/qrg