Files
evig/scripts/db/migrations/086_decisions_protocol_link.sql
Mao NakamotoandClaude Opus 4.7 6e20d9e080 feat(decisions): protocol→decision UI bridge — QQ.6 cutover
Closes ARCHITECTURE_DEBT.md #1 — protocol action items now promote to
standalone decisions instead of voting via the parallel
protocol_decision_* system.

Migration 086 applied to prod Neon (0 votes/outcomes existed there —
clean cutover, no data migration needed).

New flow:
  1. Action item with item_type='decision' shows a "Als Entscheidung
     verschieben" CTA (creator-only)
  2. Click → POST /api/decisions with protocol_id + action_item_id +
     voting_method='thumbs_up_down' + title from description +
     initialStatus='voting'
  3. Card now shows the decision's status badge + tally + "Zur
     Entscheidung" link to the full standalone decision page
  4. Voting/closure/task-creation all happen via the standalone system

Code changes:
  - DecisionBridge.tsx (new) — the thin wrapper, takes
    linkedDecision summary + isProtocolCreator
  - DecisionActions.tsx (deleted) — legacy inline thumbs voting
  - decisions-crud.ts — createDecision accepts protocolId/actionItemId;
    new getDecisionsByProtocolId() service
  - createDecisionSchema — accepts optional protocolId + actionItemId
  - review.ts — counts now use ProtocolDecisionSummary instead of
    decisionVotes/outcomes; openDecisions = decisions without a linked
    standalone OR linked but not closed
  - protocols.ts service — exports getDecisionsByProtocolId; legacy
    voting service marked deprecated (still exported until separate
    cleanup commit drops the routes + tables)
  - ProtocolDetailClient — prop name shift: decisionVotes+decisionOutcomes
    → protocolDecisions
  - ProtocolActionItemsList — same prop name shift; ActionRow renders
    DecisionBridge instead of DecisionActions
  - Tests updated to use protocolDecisions: []

Remaining cleanup (future commit):
  - /api/protocols/[id]/decisions/{vote,close,propose,create-tasks} routes
  - protocols-voting.ts service
  - protocol_decision_votes + protocol_decision_outcomes tables (DROP via
    new migration 087)
  - DecisionVoteRecord + DecisionOutcomeRecord types

typecheck: clean. production build: succeeds. 593/593 protocol+
decisions tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-05 09:24:17 +02:00

38 lines
1.8 KiB
SQL

-- 086 — Decisions: link to source protocol/action item
--
-- Step 1 of unifying the two decision systems documented in
-- docs/ARCHITECTURE_DEBT.md #1. Adds nullable foreign keys so a
-- standalone decision can reference the protocol meeting + action
-- item it came from. Existing decisions remain unaffected (both
-- columns default NULL).
--
-- Next steps (separate migration, when the UI lands):
-- - Migrate existing protocol_decision_votes + protocol_decision_outcomes
-- into decisions + decision_votes.
-- - Drop the protocol_decision_* tables.
--
-- This migration alone is safe to run any time. Reversible:
-- ALTER TABLE decisions DROP COLUMN action_item_id, DROP COLUMN protocol_id;
--
-- 2026-06-04
-- =============================================================================
ALTER TABLE decisions
ADD COLUMN IF NOT EXISTS protocol_id uuid REFERENCES meeting_protocols(id) ON DELETE CASCADE,
ADD COLUMN IF NOT EXISTS action_item_id text;
-- Lookup index for "all decisions that came from this protocol" + uniqueness:
-- one decision per (protocol, action_item) pair. action_item_id is a string ID
-- from the AI-extracted notes.action_items array, not a foreign key.
CREATE UNIQUE INDEX IF NOT EXISTS decisions_protocol_action_item_uniq
ON decisions (protocol_id, action_item_id)
WHERE protocol_id IS NOT NULL AND action_item_id IS NOT NULL;
-- Record in the migration tracking table (per scripts/db/migrations/083 bootstrap).
-- The schema_migrations table tracks by filename (not version) — same shape the
-- run-migration.sh runner uses, so this file applies correctly via direct psql
-- OR via the runner without double-insert.
INSERT INTO schema_migrations (filename)
VALUES ('086_decisions_protocol_link.sql')
ON CONFLICT (filename) DO NOTHING;