-- Migration: Add unique constraint for ON CONFLICT in StructuredStore
-- Date: 2025-11-28
-- Story: 4.1 - Structured Store (PostgreSQL)

-- Add unique constraint for idempotent operations
-- This constraint is required for the ON CONFLICT clause in StructuredStore
ALTER TABLE extracted_records
ADD CONSTRAINT IF NOT EXISTS unique_record
UNIQUE (document_id, sheet_name, row_number);

-- Verify the constraint was added
SELECT conname, contype, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE conname = 'unique_record';
