-- Migration 002 may already have run on a legacy database before its
-- skill_name constraint reconciliation was added. Relax that obsolete column
-- in a separately versioned migration so current installations are repaired.
DO $$
BEGIN
    IF EXISTS (
        SELECT 1
        FROM information_schema.columns
        WHERE table_schema = current_schema()
          AND table_name = 'execution_receipts'
          AND column_name = 'skill_name'
          AND is_nullable = 'NO'
    ) THEN
        EXECUTE 'ALTER TABLE execution_receipts
                 ALTER COLUMN skill_name DROP NOT NULL';
    END IF;
END
$$;
