fix: configuration_items sync — correct camelCase field mapping, store all UDFs in udfs JSONB

- Fix mapConfigurationItem() to use Autotask camelCase field names (was using
  snake_case keys that never matched, leaving costs/Datto/RMM fields empty)
- Map all 60+ fields explicitly: costs, Datto device fields, RMM audit fields,
  location, vendor, SNMP, backup dates, source cost, etc.
- Store entire userDefinedFields array as udfs JSONB (keyed by UDF name)
- Retain backup_type_udf VARCHAR column for backward compat
- Migration 052: add udfs JSONB column + GIN index to configuration_items
This commit is contained in:
lorentz 2026-03-17 15:39:42 -04:00
parent 0f1083f5b6
commit cb293ea843
2 changed files with 107 additions and 25 deletions

View file

@ -0,0 +1,16 @@
-- ============================================================================
-- 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().