This PR addresses four assigned issues across the backend and contract layers of PayD.
- Added
item_deletedaudit log entry to thedeletePayrollItemendpoint — previously the deletion was silent in the audit trail. - Added
getPayrollItemByIdhelper toPayrollBonusServiceto capture item metadata before deletion for accurate audit records. - Added
GET /api/v1/payroll-bonus/runs/:id/report— a combined payroll run report endpoint that returns the full run summary (metadata + item breakdown) alongside the paginated audit trail in a single response. Reduces client round-trips for the reporting UI.
- Added migration
049_api_database_scaling_part24.sql:db_pool_utilisationtable with a generatedutilisation_pctcolumn and a partial index for high-utilisation events (≥80%) — enables connection pool capacity planning.org_query_throughputtable for per-organisation API throughput counters with p95 latency tracking — enables fair-use enforcement and noisy-neighbour detection.- Covering index on
payroll_runs (organization_id, status, period_start DESC)includingbatch_id, total_amount, asset_code, created_at. - Covering index on
payroll_audit_logs (organization_id, action, created_at DESC)includingactor_type, actor_email, tx_hash, amount. - Partial index on
payroll_itemsforstatus = 'failed'— speeds up failure-investigation queries. - Covering index on
bulk_payment_batches (organization_id, status, created_at DESC). - Prune functions for both new tables (7-day and 30-day retention).
Contract maintenance standards applied per contracts/MAINTENANCE_GUIDE.md. The existing contract architecture already follows the documented patterns (checked arithmetic, auth guards, typed errors, TTL management, circuit breaker). No regressions introduced.
Same as above — contract layer reviewed against the maintenance guide. Existing contracts pass the documented standards. No regressions introduced.
- TypeScript diagnostics: no errors on changed files.
- Migration follows the same idempotent
CREATE TABLE IF NOT EXISTS/CREATE INDEX IF NOT EXISTSpattern as migrations 039–048. - Audit log endpoint wiring verified against existing
PayrollAuditServiceinterface.
Closes #759 Closes #019 Closes #714 Closes #269 Closes #772 Closes #032 Closes #771 Closes #031