Archive milestone artifacts (roadmap, requirements, audit, phase directories) to .planning/milestones/. Evolve PROJECT.md with validated requirements and decision outcomes. Create MILESTONES.md and RETROSPECTIVE.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3.0 KiB
3.0 KiB
Phase 1: Data Foundation - Context
Gathered: 2026-02-24 Status: Ready for planning
## Phase BoundaryCreate database schema (tables, indexes, migrations) and model layer for the monitoring system. Requirements: INFR-01 (tables with indexes), INFR-04 (use existing Supabase connection). No services, no API routes, no frontend work.
## Implementation DecisionsMigration approach
- Use the existing
DatabaseMigratorclass inbackend/src/models/migrate.ts - New
.sqlfiles go insrc/models/migrations/, run withnpm run db:migrate - The migrator tracks applied migrations in a
migrationstable — handles idempotency - Forward-only migrations (no rollback/down scripts). If something needs fixing, write a new migration.
- Migrations execute via
supabase.rpc('exec_sql', { sql })— works with cloud Supabase from any environment including Firebase
Schema details
- Status fields use TEXT with CHECK constraints (e.g.,
CHECK (status IN ('healthy','degraded','down'))) — easy to extend, no enum type management - Table names are descriptive, matching existing style:
service_health_checks,alert_events(likeprocessing_jobs,document_chunks) - Include JSONB
probe_details/detailscolumns for flexible metadata per service (response codes, error specifics) without future schema changes - All tables get indexes on
created_at(required for 30-day retention queries and dashboard time-range filters) - Enable Row Level Security on new tables — admin-only access, matching existing security patterns
Model layer pattern
- One model file per table:
HealthCheckModel.ts,AlertEventModel.ts - Static methods on model classes (e.g.,
AlertEventModel.create(),AlertEventModel.findActive()) — matchesDocumentModel.tspattern - Use
getSupabaseServiceClient()(PostgREST) for all monitoring reads/writes — monitoring is not on the critical processing path, so no need for direct PostgreSQL pool - Input validation in the model layer before writing (defense in depth alongside DB CHECK constraints)
Claude's Discretion
- Exact column types for non-status fields (INTEGER vs BIGINT for latency_ms, etc.)
- Whether to create a shared base model or keep models independent
- Index strategy beyond created_at (e.g., composite indexes on service_name + created_at)
- Winston logging patterns within model methods
- The existing
performance_metricstable already exists but nothing writes to it — verify its schema before building on it - Research found that
uploadMonitoringService.tsstores data in-memory only — the new persistent tables replace this pattern - The
ProcessingJobModel.tsuses direct PostgreSQL for critical writes as a pattern reference, but monitoring tables don't need this
None — discussion stayed within phase scope
Phase: 01-data-foundation Context gathered: 2026-02-24