# Indirect Goods Upgrade — Phase 1 Schema Completion

Completed: 11 July 2026

## Outcome

Phase 1 added the database foundation for indirect issue parity and FOC-only returns. No new workflow was enabled and no existing stock or request quantity was changed.

## Migrations

- `2026_07_11_000002_create_indirect_goods_issue_parity_tables.php`
- `2026_07_11_000003_extend_indirect_goods_workflow_tables.php`

## New tables

1. `indirect_goods_fulfillments`
2. `indirect_goods_fulfillment_allocations`
3. `indirect_goods_direct_deliveries`
4. `indirect_goods_direct_delivery_items`
5. `indirect_goods_foc_inventory`
6. `indirect_goods_foc_adjustments`
7. `indirect_goods_returns`
8. `indirect_goods_return_items`
9. `indirect_goods_division_deliveries`

All nine tables were created empty, as required before Phase 3 backfill or later workflow activation.

## Extended tables

### `indirect_goods_requests`

- Added optimistic `lock_version`.
- Added `closed_at` and `closed_by` audit fields.

### `indirect_goods_request_items`

- Added `fulfillment_status`.
- Added optimistic `lock_version`.

### `indirect_goods_stock_movements`

- Expanded movement types for returns, FOC, transfers and reversals.
- Added project, request item, fulfillment and return-item references.
- Added source/destination ledger and inventory references.

### `indirect_goods_project_inventory`

- Added provenance lookup index across project, division, item and invoice.

## Safety controls included

- Restrictive foreign keys for issued history.
- Nullable audit foreign keys where user/source deletion is allowed.
- Unique document numbers.
- Unique nullable idempotency keys on stock-changing headers.
- Explicit source, request, project, division and status indexes.
- Decimal precision suitable for quantity and valuation tracking.
- Soft deletes only on document/inventory headers where historical retention is required.

## Verification

- Both migration files pass PHP syntax checks.
- Both migrations applied successfully.
- Rollback of the complete Phase 1 batch succeeded.
- Reapplication after rollback succeeded.
- Every new table and required extension column was verified.
- New-table row total after migration: 0.

## Post-migration baseline

| Metric | Before Phase 1 | After Phase 1 | Variance |
|---|---:|---:|---:|
| Warehouse available | 178,264.48 | 178,264.48 | 0.00 |
| Project available | 23,829.02 | 23,829.02 | 0.00 |
| Project consumed | 2.00 | 2.00 | 0.00 |
| Request released | 23,831.02 | 23,831.02 | 0.00 |
| Request balance | 782.00 | 782.00 | 0.00 |

## Phase gate

Phase 1 is complete. Phase 2 may create the domain models and transactional services, but must not backfill historical rows or switch live issue behavior; those remain Phase 3 and Phase 4 responsibilities.
