-- Migration 025: Add 'abandoned' status to sessions
-- Purpose: Fix CF-572 schema constraint issue preventing orphan recovery
-- Context: sessionRecoverOrphaned() tries to set status='abandoned' but constraint only allows 'active', 'completed', 'interrupted'

ALTER TABLE sessions
  DROP CONSTRAINT IF EXISTS sessions_status_check;

ALTER TABLE sessions
  ADD CONSTRAINT sessions_status_check
  CHECK (status IN ('active', 'completed', 'interrupted', 'abandoned'));

COMMENT ON CONSTRAINT sessions_status_check ON sessions
  IS 'Valid session statuses including abandoned for orphaned sessions (CF-572)';
