Files
Agent-System/deploy/postgres/migrations/2026-09-09-uq-context-memory-chunk-hash.sql
T

15 lines
506 B
SQL

-- 修复 IndexApprovedDocument: ON CONFLICT (chunk_hash) 需要唯一约束
DELETE FROM context_memory_chunks a
USING context_memory_chunks b
WHERE a.chunk_hash IS NOT NULL
AND a.chunk_hash <> ''
AND a.chunk_hash = b.chunk_hash
AND a.id > b.id;
UPDATE context_memory_chunks
SET chunk_hash = 'legacy_empty_' || id::text
WHERE chunk_hash IS NULL OR chunk_hash = '';
DROP INDEX IF EXISTS idx_mem_chunks_hash;
CREATE UNIQUE INDEX IF NOT EXISTS uq_mem_chunks_hash ON context_memory_chunks(chunk_hash);