Parts
Device- or herd-scoped hardware parts with serial and product numbers
| Column Name | Data Type | Constraints |
|---|---|---|
| id | bigint | NOT NULL |
| created_at | timestamp with time zone | DEFAULT now() NOT NULL |
| device_id | bigint | FK -> devices |
| herd_id | bigint | FK -> herds |
| serial_number | text | NOT NULL |
| product_number | text | NOT NULL, FK -> product_numbers |
| certificate_id | bigint | FK -> certificates |
| primary_calibration_id | bigint | FK -> calibrations |
| health | public.health_item | DEFAULT 'healthy' NOT NULL |
| updated_at | timestamp with time zone | DEFAULT now() |
| lifecycle | public.entity_lifecycle | DEFAULT 'active' NOT NULL |
| lifecycle_changed_at | timestamp with time zone | DEFAULT timezone('utc'::text, now()) NOT NULL |
| lifecycle_changed_by | uuid | |
| lifecycle_reason | text |
Exactly one of device_id or herd_id is set (parts_exactly_one_scope).
Security Policies (RLS)
RLS enabled. Herd scope: COALESCE(parts.herd_id, get_herd_id_by_device_id(parts.device_id)).
| Operation | has_herd_ability ability key | Other paths |
|---|---|---|
| SELECT | devices.read | Device API key (own or herd) |
| INSERT | devices.write | Owning device API key |
| UPDATE | devices.write | Owning device API key |
| DELETE | devices.write | Owning device API key |
Platform superadmin: FOR ALL bypass where defined.