mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-04 05:37:00 +01:00
Creating a protocol from an audio recording failed on prod: migration 027b used ADD COLUMN IF NOT EXISTS ... CHECK, which silently skips the CHECK when the column already exists — so the stale input_method value list (without 'audio') survived and rejected every valid audio insert. Migration 134 guarantees the input_method column exists and drops all CHECK constraints on meeting_protocols + protocol_action_links by catalog lookup. All of them are hand-synced enum lists already validated at the write boundary via zod schemas derived from src/config/protocols.ts — same policy as migration 110 (notifications). Verified by replaying both the fresh-from- zero and the drifted-prod state in a throwaway Postgres 16. Create form (/admin/protocols/new) noise reduction: - Open-source fallback tools (CaptureAlternatives) move out of the middle of the hero card to a collapsed disclosure at the page bottom — reference material, not part of the flow. - Hero hierarchy now matches usage: drop zone first, record button with its consent checkbox beside it, notes textarea last; the filler "oder / Datei hochladen ↓" spans are gone. - Submit is a plain action row instead of a third card; the format/char-count meta line only renders once there is text. Claude-Session: https://claude.ai/code/session_01QXEBWjhBB9JYsgLSX4jNES Co-authored-by: Georgy Butaev <georgy.butaev@revamp-it.ch> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
50 lines
2.1 KiB
SQL
50 lines
2.1 KiB
SQL
-- Migration 134: protocols — guarantee input_method exists, drop legacy enum CHECKs
|
|
--
|
|
-- Prod incident (2026-07-16): creating a protocol with input_method='audio'
|
|
-- failed the INSERT. Root cause: migration 027b used
|
|
-- `ADD COLUMN IF NOT EXISTS input_method ... CHECK (...)`. On databases where
|
|
-- the column already existed, the whole ALTER is a silent no-op — so the CHECK
|
|
-- that includes 'audio' never replaced the older hand-synced value list, and
|
|
-- the DB kept rejecting valid app-level values.
|
|
--
|
|
-- Same failure class as notifications_type_check (dropped in migration 110):
|
|
-- an app-level enum duplicated into a DB CHECK drifts and rejects valid
|
|
-- values. All CHECKs on the protocol tables are enum value lists, validated
|
|
-- at the write boundary:
|
|
-- meeting_type / visibility / input_method → createProtocolSchema /
|
|
-- updateProtocolSchema (zod, derived from src/config/protocols.ts)
|
|
-- status → written only by internal services using config constants
|
|
-- link_type → linkActionSchema (zod)
|
|
-- Neither table has range/money/date-ordering CHECKs, so dropping all CHECK
|
|
-- constraints on them is safe.
|
|
--
|
|
-- Policy (CLAUDE.md): app-level enums = config constant + zod at the write
|
|
-- boundary. DB CHECKs are reserved for true invariants.
|
|
|
|
-- 1. Guarantee the column exists (no-op where 027b already ran fully).
|
|
ALTER TABLE meeting_protocols
|
|
ADD COLUMN IF NOT EXISTS input_method TEXT DEFAULT 'transcript';
|
|
|
|
-- 2. Drop every CHECK constraint on the protocol tables. Constraint names
|
|
-- vary between environments (inline CREATE TABLE vs ALTER-added), so drop
|
|
-- by catalog lookup instead of guessing names.
|
|
DO $$
|
|
DECLARE
|
|
con RECORD;
|
|
BEGIN
|
|
FOR con IN
|
|
SELECT conrelid::regclass AS tbl, conname
|
|
FROM pg_constraint
|
|
WHERE contype = 'c'
|
|
AND conrelid IN (
|
|
'meeting_protocols'::regclass,
|
|
'protocol_action_links'::regclass
|
|
)
|
|
LOOP
|
|
EXECUTE format('ALTER TABLE %s DROP CONSTRAINT %I', con.tbl, con.conname);
|
|
END LOOP;
|
|
END $$;
|
|
|
|
COMMENT ON COLUMN meeting_protocols.input_method
|
|
IS 'Pipeline entry point: audio | transcript | notes | tasks — validated in app (src/config/protocols.ts), no DB CHECK (migration 134)';
|