-- ============================================================================
-- Add udfs JSONB column to configuration_items to store all Autotask UDFs
-- ============================================================================

-- Generic JSONB store for all UDFs returned from Autotask userDefinedFields
ALTER TABLE configuration_items
    ADD COLUMN IF NOT EXISTS udfs JSONB;

-- Index for UDF queries (GIN for JSONB containment/key lookups)
CREATE INDEX IF NOT EXISTS idx_configuration_items_udfs
    ON configuration_items USING GIN (udfs);

-- Note: all other schema columns (costs, Datto fields, RMM audit fields, etc.)
-- already existed from 001_initial_schema.sql. The mapper was writing them with
-- snake_case keys instead of reading from the camelCase Autotask response — that
-- was a code-only bug fixed in lib/utils/entity-mapper.ts mapConfigurationItem().
