# D2: Actor for automatically generated WO history

Status: Option 1 APPROVED by the user: "ya gunakan rekomendasi saja". Implement nullable system actor, preserve authenticated actor attribution. Application deployment remains separately instructed.

The current WorkOrderStatusHistory requires changedById and a User relation. A scheduled generator has no authenticated human actor. AuditLog already supports a nullable actor, but WO history does not. Assigning the plan creator to a later automated event would imply they executed it, so that fallback is not implemented.

## Option 1 (recommended): explicit system event

Change only these fields in WorkOrderStatusHistory:

```prisma
changedById String? @db.VarChar(30)
changedBy User? @relation(fields: [changedById], references: [id], onDelete: Restrict)
```

Additive compatibility migration:

```sql
ALTER TABLE `WorkOrderStatusHistory` MODIFY COLUMN `changedById` VARCHAR(30) NULL;
```

Preserve existing values, index and FK. Check MySQL FK compatibility in the isolated migration test; if needed recreate the same FK around the nullable-column alteration. Update ERD nullable marker and cardinality. New scheduler-generated OPEN history uses null actor with an explicit automatic-generation note. API history actor becomes `{ id, name } | null`; frontend renders null as “Sistem”. Authenticated user actions must always retain their actual actor; clients cannot submit actor IDs or request a null actor.

## Option 2: dedicated system account

Preserve the existing schema. Provision a dedicated noninteractive User and require scheduler configuration to identify it. Define the account's login/activation policy before implementation so it does not become a normal shared login. API can retain a non-null actor shape. This requires account provisioning and operational configuration beyond D1.

Implemented in maintenance-plans.service.ts and prisma/generate-maintenance.ts. The draft has been removed. Isolated tests pass for nullable actor migration, historical preservation, foreign-key integrity, concurrency, restarts, catch-up, ONCE, pause and archived targets. The scheduler command also passed against the isolated database. Frontend WorkOrderHistory displays “Sistem” for null actors; the existing server detail route includes it. Deployment is not activated.
