shoc-backend/docs/work-orders/phase-0/database-drift-report.md

110 lines
3.5 KiB
Markdown

# Database Drift Report — SQL vs EF
**Fase:** 0
**Data:** 2026-06-24
**EF Snapshot:** `Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs`
**Script legado:** `Api.SeaHavenIndustries/db.txt`
---
## 1. Metodologia
1. Colunas EF extraídas do `ApplicationDbContextModelSnapshot` (entidade `WorkOrder`).
2. Colunas SQL legado extraídas de `db.txt` DDL `[WorkOrders]`.
3. Classificação: **mapear**, **deprecar**, **satélite**, **OK**.
---
## 2. Tabela workOrders — drift conhecido
| Coluna SQL (legado) | No EF? | Classificação | Ação Fase 0 |
|---------------------|--------|---------------|-------------|
| WorkOrderType | **Não** | mapear | Adicionar `WorkOrderType` int nullable → enum |
| AvettaTask | **Não** | inventariar | Adicionar coluna nullable; uso TBD com PO |
| AssignDate | **Não** | inventariar | Adicionar coluna nullable; possível alias AssignDate tracking |
| Nome tabela WorkOrders vs workOrders | EF usa `workOrders` | OK | Manter EF naming; SQL Server case-insensitive |
---
## 3. Colunas EF (workOrders) — baseline
Presentes no snapshot e mapeadas:
InternalWONumber, ExternalWorkOrderId, WorkerOrderNumber, WorkerOrderTitle, Description, Customer, SiteCode, Building, Severity, DateReported, ScheduledStart, ScheduledDate, CompletedDate, Source, SourceEmailS3Key, Problem, Trade, SubTrade, VendorNTE, AssignTo, DueDate, Priority, Status, LocationId, PO, TT, Attachments, BeforPhoto*, AfterPhoto*, SignOff*, istemplate, audit fields (CreatedDate, IsDeleted, etc.)
---
## 4. Novas colunas Fase 0 (migration)
| Coluna | Tipo | Slice |
|--------|------|-------|
| LifecycleStatus | int nullable | Core |
| LegacyStatus | nvarchar (cópia Status) | Core |
| WorkOrderType | int nullable | Core |
| PrimaryDispatchId | int nullable FK | Core |
| RowVersion | rowversion | Core |
| TargetWeek | date nullable | Scheduling |
| ScheduledEnd | datetime2 nullable | Scheduling |
| ScheduleWeekOnly | bit nullable | Scheduling |
| OriginalWeek | date nullable | Tracking |
| OriginalDate | date nullable | Tracking |
| RescheduleCount | int default 0 | Analytics |
| CarriedOver | int default 0 | Analytics |
| DocStatus | int nullable | Completion |
| AvettaTask | nvarchar max nullable | Legado SQL |
| AssignDate | date nullable | Legado SQL |
---
## 5. Dispatch
| Item | EF | Ação Fase 0 |
|------|-----|-------------|
| RowVersion | Ausente | Adicionar |
| Demais colunas | OK | Manter |
---
## 6. WorkOrderAuditLog
| Coluna | EF atual | Ação Fase 0 |
|--------|----------|-------------|
| EventType | Ausente | Adicionar |
| ActorType | Ausente | Adicionar |
| DispatchId | Ausente | Adicionar nullable |
| CorrelationId | Ausente | Adicionar nullable |
---
## 7. WorkOrderContacts
| Coluna | EF | Ação Fase 0 |
|--------|-----|-------------|
| Notes | Ausente | Adicionar nvarchar nullable (pocNotes) |
---
## 8. ApplicationUser (AspNetUsers)
| Coluna | Ação Fase 0 |
|--------|-------------|
| Initials | nvarchar(8) nullable |
| Color | nvarchar(16) nullable |
---
## 9. Tabelas revisadas — sem drift crítico adicional
- `Comments` — OK
- `Locations` — OK (SiteCode via WO.SiteCode)
- `DispatchWorkOrders` — OK
---
## 10. Recomendações
1. **Eliminar dual-path:** `db.txt` catch-up não deve ser usado após migration EF Phase0; documentar em runbook.
2. **WorkOrderType:** mapear valores SQL existentes → enum na migration data script (dry-run).
3. **AvettaTask / AssignDate:** manter nullable; PO valida uso antes de exposição board.
**Gate:** Diff assinado por Backend antes de merge migration.