-- Add 'finance' value to UserRole enum type
-- This is needed because we added a new finance role to the dynamic RBAC system

BEGIN;

-- Add the finance value to the userrole enum if it doesn't already exist
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM pg_enum
        WHERE enumlabel = 'finance'
        AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'userrole')
    ) THEN
        ALTER TYPE userrole ADD VALUE 'finance';
        RAISE NOTICE 'Added finance to userrole enum';
    ELSE
        RAISE NOTICE 'finance already exists in userrole enum';
    END IF;
END$$;

COMMIT;

-- Verify the enum values
SELECT enumlabel
FROM pg_enum
WHERE enumtypid = (SELECT oid FROM pg_type WHERE typname = 'userrole')
ORDER BY enumsortorder;
