-- Migration 028: DSFA AI Use Cases
-- Adds ai_use_case_modules (JSONB) and section_8_complete (BOOLEAN) to compliance_dsfas

ALTER TABLE compliance.compliance_dsfas
  ADD COLUMN IF NOT EXISTS ai_use_case_modules JSONB DEFAULT '[]'::jsonb,
  ADD COLUMN IF NOT EXISTS section_8_complete BOOLEAN DEFAULT FALSE;

-- Extend section_progress JSONB for existing rows (only if column exists)
DO $$
BEGIN
  IF EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'compliance'
      AND table_name = 'compliance_dsfas'
      AND column_name = 'section_progress'
  ) THEN
    UPDATE compliance.compliance_dsfas
    SET section_progress = section_progress || '{"section_8_complete": false}'::jsonb
    WHERE section_progress IS NOT NULL
      AND NOT (section_progress ? 'section_8_complete');
  END IF;
END $$;
