37 lines
2.2 KiB
SQL
37 lines
2.2 KiB
SQL
-- Retain an immutable link to the old accepted candidate. This does not create
|
|||
|
|
-- native memories or reset any historical approval/extraction state.
|
||
|
|
ALTER TABLE workbench_pending_memories
|
||
|
|
ADD COLUMN IF NOT EXISTS legacy_history_id VARCHAR(36),
|
||
|
|
ADD COLUMN IF NOT EXISTS native_memory_id VARCHAR(36),
|
||
|
|
ADD COLUMN IF NOT EXISTS reconfirmed_content TEXT,
|
||
|
|
ADD COLUMN IF NOT EXISTS reconfirmed_at TIMESTAMPTZ;
|
||
|
|
|
||
|
|
DO $legacy_memory$ BEGIN
|
||
|
|
IF to_regclass('yawan_legacy_operations_mappings') IS NOT NULL THEN
|
||
|
|
UPDATE workbench_pending_memories p
|
||
|
|
SET legacy_history_id = m.history_id
|
||
|
|
FROM yawan_legacy_operations_mappings m
|
||
|
|
JOIN workbench_history h ON h.id = m.history_id
|
||
|
|
AND h.tenant_id = m.target_tenant_id AND h.source_kind = 'pendingmemory'
|
||
|
|
AND h.source_id = m.source_id::text
|
||
|
|
WHERE m.source_kind = 'pendingmemory'
|
||
|
|
AND m.target_table = 'workbench_pending_memories'
|
||
|
|
AND m.target_key = p.id AND m.target_tenant_id = p.tenant_id
|
||
|
|
AND m.native_snapshot->>'owner_id' = p.owner_id
|
||
|
|
AND m.native_snapshot->>'agent_id' = p.agent_id
|
||
|
|
AND m.native_snapshot->>'status' = 'accepted' AND p.status = 'accepted'
|
||
|
|
AND COALESCE(p.legacy_history_id, '') = '';
|
||
|
|
END IF;
|
||
|
|
END $legacy_memory$;
|
||
|
|
|
||
|
|
-- Durable extraction retries retain all pending sessions and checkpoints.
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_attempt_id VARCHAR(36) NOT NULL DEFAULT '';
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_lease_until TIMESTAMPTZ;
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_started_at TIMESTAMPTZ;
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_next_at TIMESTAMPTZ;
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_failures INTEGER NOT NULL DEFAULT 0;
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_chat_model_id VARCHAR(64) NOT NULL DEFAULT '';
|
||
|
|
ALTER TABLE memory_subjects ADD COLUMN IF NOT EXISTS extract_language VARCHAR(64) NOT NULL DEFAULT '';
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_memory_extraction_due ON memory_subjects(extract_next_at)
|
||
|
|
WHERE enabled = TRUE AND extract_failures < 8 AND pending_sessions <> '[]'::jsonb;
|