Add Prisma schema for runner jobs, job steps, and job events to support the autonomous runner infrastructure (M4.2). Enums added: - RunnerJobStatus: PENDING, QUEUED, RUNNING, COMPLETED, FAILED, CANCELLED - JobStepPhase: SETUP, EXECUTION, VALIDATION, CLEANUP - JobStepType: COMMAND, AI_ACTION, GATE, ARTIFACT - JobStepStatus: PENDING, RUNNING, COMPLETED, FAILED, SKIPPED Models added: - RunnerJob: Top-level job tracking linked to workspace and agent_tasks - JobStep: Granular step tracking within jobs with phase organization - JobEvent: Immutable event sourcing audit log for jobs and steps Foreign key relationships: - runner_jobs → workspaces (workspace_id, CASCADE) - runner_jobs → agent_tasks (agent_task_id, SET NULL) - job_steps → runner_jobs (job_id, CASCADE) - job_events → runner_jobs (job_id, CASCADE) - job_events → job_steps (step_id, CASCADE) Indexes added for performance on workspace_id, status, priority, timestamp. Migration: 20260201205935_add_job_tracking Quality gates passed: typecheck, lint, build Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3.8 KiB
3.8 KiB
Issue #164: Database schema for job tracking
Objective
Add Prisma schema for runner_jobs, job_steps, and job_events tables to support the autonomous runner infrastructure.
Approach
- Read existing schema.prisma to understand current conventions
- Add four enums: RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus
- Add three models: RunnerJob, JobStep, JobEvent
- Create and run migration
- Verify migration succeeds
Schema Design
Enums
- RunnerJobStatus: PENDING, QUEUED, RUNNING, COMPLETED, FAILED, CANCELLED
- JobStepPhase: SETUP, EXECUTION, VALIDATION, CLEANUP
- JobStepType: COMMAND, AI_ACTION, GATE, ARTIFACT
- JobStepStatus: PENDING, RUNNING, COMPLETED, FAILED, SKIPPED
Models
-
RunnerJob - Top-level job tracking
- Links to workspace and optionally to agent_task
- Tracks overall job status, progress, result
- Timestamps: created_at, started_at, completed_at
-
JobStep - Granular step tracking
- Child of RunnerJob
- Phase-based organization (SETUP, EXECUTION, etc.)
- Token tracking for AI operations
- Duration tracking
-
JobEvent - Event sourcing audit log
- Immutable event log for jobs and steps
- Links to both job and optionally step
- Actor tracking for accountability
Progress
- Read existing schema.prisma
- Read architecture document for schema requirements
- Add enums (RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus)
- Add RunnerJob model with workspace and agentTask relations
- Add JobStep model with job relation
- Add JobEvent model with job and step relations
- Add RunnerJob[] to Workspace and AgentTask relations
- Create migration (20260201205935_add_job_tracking)
- Test migration - all tables created successfully
- Run quality gates (typecheck, lint, build - all passed)
- Generate Prisma client
- Commit changes
Schema Observations from Existing Code
Conventions Identified:
- UUID primary keys with
@db.Uuidannotation - snake_case for database column names via
@map - snake_case for table names via
@@map - Timestamps use
@db.Timestamptzfor timezone awareness - workspace_id on all workspace-scoped tables with cascading deletes
- Composite unique constraints with
@@unique([id, workspaceId]) - Consistent indexing patterns: workspace_id, status, timestamps
- Json fields for flexible metadata with
@default("{}") - Optional foreign keys use
@db.Uuidwithout NOT NULL - Relations use descriptive names in both directions
Testing
Since this is a schema-only change, testing will verify:
- Migration runs successfully ✅
- Foreign key constraints are valid ✅
- Schema matches architecture document ✅
Verification performed:
- Database tables created: runner_jobs, job_steps, job_events
- All enums created: RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus
- Foreign key relationships verified:
- runner_jobs → workspaces (workspace_id)
- runner_jobs → agent_tasks (agent_task_id, optional)
- job_steps → runner_jobs (job_id)
- job_events → runner_jobs (job_id)
- job_events → job_steps (step_id, optional)
- Indexes created for performance:
- workspace_id for workspace filtering
- status for job querying
- priority for job prioritization
- timestamp for event ordering
- Quality gates passed:
- TypeScript compilation ✅
- ESLint checks ✅
- NestJS build ✅
- Prisma client generation ✅
Notes
- Following existing patterns from schema.prisma
- Using UUID for all primary keys (existing convention)
- Using snake_case for table names (Prisma convention)
- All workspace-scoped tables include workspace_id for RLS
- Migration file created: 20260201205935_add_job_tracking
- Database push successful, migration marked as applied
- Schema format validated successfully