Skip to content

Database

Production: Neon Postgres (serverless, auto-scaling). Local dev: Postgres via Docker or local install.


Connection

Set via environment variable:

ConnectionStrings__Postgres=Host=...;Port=5432;Database=apexlab;Username=apexlab;Password=...

Schema

12 tables managed by EF Core migrations:

Table Purpose
users Accounts (OAuth + email/password)
sessions Uploaded session summaries
laps Lap rows with quality scores
tracks Canonical track records
track_versions Immutable centerline snapshots (GeoJSON)
leaderboard_entries One per (track, user) — best lap only
user_achievements Grant history
feed_entries Activity stream
refresh_tokens Hashed refresh tokens
outbox_messages Transactional event outbox
track_processing_jobs Durable queue for centerline processing
share_packs Reserved for V2

For full column-level documentation see the Data Dictionary.


SafeWatch Event Tables

Five additional tables populated by the SafeWatch instrumentation layer:

Table Purpose
api_request_events Every API request (route, status, duration)
auth_events Login, register, logout attempts
session_events Session upload events
ai_events AI coach query events + cost
leaderboard_events Leaderboard submission events

Local Dev Setup

# Start Postgres + Redis locally (Docker)
docker-compose -f SimCopilot.Api/docker-compose.yml up -d

# Apply migrations
cd SimCopilot.Api/src/SimCopilot.Api
dotnet ef database update

Migrations

# Generate a new migration
dotnet ef migrations add <MigrationName>

# Apply all pending migrations
dotnet ef database update

# Revert last migration
dotnet ef migrations remove