Database Schema (ST-102)
Overview
Implements the foundational PostgreSQL database schema using Prisma ORM. Includes core tables for users, repositories, test cases, test runs, flake scores, and supporting entities.
Core Tables
Repo
Stores repository information.
id- UUID primary keyghId- GitHub repository ID (unique)name- Repository nameowner- Repository ownerdefaultBranch- Default branch (default: "main")visibility- Repository visibility (public/private)config- JSONB configurationcreatedAt- Creation timestampupdatedAt- Last update timestamp
User
Stores user accounts.
id- UUID primary keygithubId- GitHub user ID (unique, nullable)githubLogin- GitHub username (nullable)email- User email (nullable)name- Display name (nullable)createdAt- Account creation timestamplastLoginAt- Last login timestamptelemetryOptIn- Telemetry opt-in flagpreferences- JSONB user preferences
TestCase
Stores test case metadata.
id- UUID primary keyrepoId- Foreign key to reposname- Test nameframework- Testing frameworkfilePath- Test file pathcreatedAt- Creation timestampupdatedAt- Last update timestamp
TestRun
Stores test run results.
id- UUID primary keyrepoId- Foreign key to repostestCaseId- Foreign key to test_casescommitSha- Git commit SHArunId- CI run identifierstatus- Test status (passed/failed/skipped)duration- Test duration (milliseconds)failureDetails- JSONB failure detailscreatedAt- Run timestamp
FlakeScore
Stores flake detection scores.
id- UUID primary keytestCaseId- Foreign key to test_casesscore- Flake score (0-100)confidence- Confidence levelfactors- JSONB contributing factorscalculatedAt- Calculation timestamp
Authentication Tables
Account
OAuth account linkage.
id- UUID primary keyuserId- Foreign key to usersprovider- OAuth provider (e.g., "github")providerAccountId- Provider user IDaccessToken- Encrypted access tokenrefreshToken- Encrypted refresh tokenexpiresAt- Token expiration timestamp
Session
User sessions.
id- UUID primary keyuserId- Foreign key to userssessionToken- JWT session token (unique)expires- Session expiration timestampcreatedAt- Session creation timestamp
RBAC Tables
UserRepoRole
Repository role assignments.
id- UUID primary keyuserId- Foreign key to usersrepoId- Foreign key to reposrole- Role enum (admin/member/read_only)createdAt- Assignment timestamp
RoleAuditLog
Role change audit trail.
id- UUID primary keyuserId- Target user IDrepoId- Repository IDaction- Action (assigned/removed)role- Role assigned/removedactorId- User who made the changecreatedAt- Change timestamp
Security Tables
AuditLog
Security audit logs.
id- UUID primary keyactorId- User who performed actionaction- Action enum (login_success, role_assigned, etc.)subject- Subject enum (user, repo, security, etc.)subjectId- Subject identifierdescription- Action descriptionmetadata- JSONB metadataipAddress- Request IP addressuserAgent- Request user agentcreatedAt- Log timestamp
HmacSecret
HMAC secrets for CI authentication.
id- UUID primary keyrepoId- Foreign key to reposname- Secret namesecretHash- Hashed secret valueactive- Active flagrevoked- Revoked flaglastUsedAt- Last usage timestampcreatedAt- Creation timestamprevokedAt- Revocation timestampexpiresAt- Expiration timestamprotatedFrom- Previous secret ID (rotation)
DSR Tables
DataSubjectRequest
Data subject requests (GDPR/CCPA).
id- UUID primary keyuserId- Foreign key to userstype- Request type (export/deletion)status- Request status (pending/processing/completed/failed)exportData- JSONB export payloaddueAt- SLA deadlineprocessedAt- Processing timestampcreatedAt- Request timestamp
DataSubjectRequestEvent
DSR event timeline.
id- UUID primary keyrequestId- Foreign key to data_subject_requestsstatus- Event statusnotes- Event notescreatedAt- Event timestamp
Indexes
- Primary keys on all tables
- Foreign key indexes
- Unique constraints where needed
- Composite indexes for common queries
- GIN indexes on JSONB fields
Migrations
Prisma migrations are versioned and reversible:
npm run db:migrate # Apply migrations
npm run db:migrate:deploy # Deploy to production
Migration files: libs/database/prisma/migrations/
Schema Management
Generate Prisma Client
npm run db:generate
View Schema
npm run db:studio
Opens Prisma Studio for database browsing.
Related Documentation
- Prisma Documentation
- PostgreSQL Documentation
- Authentication - Auth tables
- RBAC - Role tables