# Data Model — Inventory Dependencies Graph (042)

## Entities

### InventoryItem
Existing entity (Spec 040).

Key fields used by this feature:
- `tenant_id` (FK)
- `external_id` (string; stable identifier used as edge endpoint)
- `policy_type` (string)
- `display_name` (nullable string)
- `meta_jsonb` (array/jsonb; safe subset)

### InventorySyncRun
Existing entity used for observability of sync operations.

Key fields used by this feature:
- `tenant_id`
- `selection_hash`
- `selection_payload` (array)
- `status` (running/success/partial/failed/skipped)
- `had_errors` (bool)
- `error_codes` (array)
- `error_context` (array)

For MVP warnings persistence:
- `error_context.warnings[]` (array of warning objects)
- Warning object shape (stable): `{type: 'unsupported_reference', policy_id, raw_ref, reason}`

### InventoryLink
Dependency edge storage.

Fields:
- `tenant_id`
- `source_type` (string; MVP uses `inventory_item`)
- `source_id` (string; stores `InventoryItem.external_id`)
- `target_type` (string; `inventory_item` | `foundation_object` | `missing`)
- `target_id` (nullable string; null when missing)
- `relationship_type` (string; values from RelationshipType enum)
- `metadata` (jsonb)
- timestamps

Unique key (idempotency):
- `(tenant_id, source_type, source_id, target_type, target_id, relationship_type)`

#### InventoryLink.metadata
Common keys:
- `last_known_name` (nullable string)
- `raw_ref` (mixed/array; only when safe)

Required when `target_type='foundation_object'`:
- `foundation_type` (string enum-like): `aad_group` | `scope_tag` | `device_category` | `assignment_filter`
Additional metadata (when applicable):
- `filter_mode` (string enum-like): `include` | `exclude` (for `foundation_type='assignment_filter'`)
## Enums

### RelationshipType
- `assigned_to`
- `assigned_to_include`
- `assigned_to_exclude`
- `uses_assignment_filter`
- `scoped_by`
- `targets`
- `depends_on`

## Relationships

- InventoryItem (source) has many outbound InventoryLinks via `source_id` + `tenant_id`.
- InventoryItem (target) has many inbound InventoryLinks via `target_id` + `tenant_id` where `target_type='inventory_item'`.

## Constraints / Limits

- Query: limit-only, ordered by `created_at DESC`.
- UI: max 50 per direction (<=100 combined).
- Extraction: max 50 outbound edges per item; unknown shapes are warning-only.
