Files
HealthLog/prisma/migrations/0207_mcp_phase5_write_surface/migration.sql
T
Marc-André Bombeck fb986bc09d merge: bring the MCP server onto the v1.23 base
Combine the remote MCP server (stdio + remote /mcp + OAuth 2.1 + read
tools + deep-value reads + a confirmed, audience-bound write surface)
with the v1.23 account-security line (MFA, known/trusted devices,
free-text note encryption).

- schema: keep every v1.23 User relation (MFA, known/trusted devices)
  alongside the McpOAuthConnection relation; the MeasurementSource enum
  carries the MCP value.
- api-handler: the MCP audience guard (a token scoped to
  health:read/health:write is bound to /mcp and refused a REST write)
  and the step-up MFA helpers coexist.
- maintenance queues: register the MCP token-cleanup sweep next to the
  note-encryption backfill and key-rotation queues; shift it to 04:00
  so the two daily discovery ticks do not collide.
- migrations: renumber the MCP migrations to 0206/0207 so they follow
  the v1.23 chain (0199-0205).
- MCP mood writes route the note through the v1.23 at-rest cipher.
2026-06-28 00:52:04 +02:00

15 lines
812 B
SQL

-- MCP write provenance.
--
-- The remote MCP endpoint gains a confirmed write surface (logging a
-- measurement / mood). Rows it writes carry their own `MeasurementSource`
-- value so they are distinguishable from MANUAL / TELEGRAM provenance and
-- get an isolated idempotency namespace `(userId, type, MCP, externalId)`.
--
-- Purely-additive enum extension; no row touched. `ADD VALUE IF NOT EXISTS`
-- makes a rerun safe. The new value is NOT used elsewhere in this migration,
-- so it is safe to extend the enum in the same step (Postgres only forbids
-- USING a freshly-added value in the same transaction). Mirrors the 0189
-- source-extension that added TELEGRAM. The enum is `@@map`-ed to the
-- snake_case type name `measurement_source`.
ALTER TYPE "measurement_source" ADD VALUE IF NOT EXISTS 'MCP';