Files
paliad/internal/db/migrations/070_paliadin_inline.down.sql
m 282e0bb237 feat(paliadin/migration-070): t-paliad-161 Slice A — schema for agent-suggested write path
Two coordinated additions:

1. paliad.approval_requests gets requester_kind text NOT NULL DEFAULT
   'user' CHECK ('user','agent') + agent_turn_id uuid REFERENCES
   paliadin_turns(turn_id) ON DELETE SET NULL. The xor-check pins
   (kind='agent' ↔ agent_turn_id IS NOT NULL) so agent rows can't lose
   provenance and user rows can't accidentally pick up a turn id.
   Existing rows backfill cleanly via the DEFAULT.

2. paliad.paliadin_turns.context jsonb — structured page-context
   payload (route_name + primary_entity + selection + view hints) the
   inline widget submits with every turn. Old page_origin column stays
   as the cosmetic URL field.

Idempotent — every ALTER uses IF NOT EXISTS and the constraints/index
are guarded by DO blocks. Verified live via BEGIN..ROLLBACK on the
production DB: cols + 3 constraints + index land cleanly, second apply
is a no-op, xor-check rejects ('agent', NULL).

Skipped the optional PaliadinRelay interface extraction per the design
doc's own §6.4 caveat: paliadin.go + paliadin_remote.go already share
the paliadinDB substrate cleanly; introducing an interface now would
duplicate without removing duplication. Reserves the seam for the
future API cutover without paying its cost today.

Refs: docs/design-paliadin-inline-2026-05-08.md §7.1, §4.2, §6.4.
2026-05-08 19:42:05 +02:00

16 lines
548 B
SQL

-- Reverse t-paliad-161 — drop the inline-Paliadin migration.
DROP INDEX IF EXISTS paliad.approval_requests_agent_turn_idx;
ALTER TABLE paliad.approval_requests
DROP CONSTRAINT IF EXISTS approval_requests_agent_xor,
DROP CONSTRAINT IF EXISTS approval_requests_agent_turn_fk,
DROP CONSTRAINT IF EXISTS approval_requests_requester_kind_check;
ALTER TABLE paliad.approval_requests
DROP COLUMN IF EXISTS agent_turn_id,
DROP COLUMN IF EXISTS requester_kind;
ALTER TABLE paliad.paliadin_turns
DROP COLUMN IF EXISTS context;