# Database Layer Hardening Plan ## Goal Ensure database access patterns are efficient, resilient, and match schema constraints across `pkg/database` and integrations. ## Tasks 1. **Schema & Migrations** - [ ] Review current schema/migrations (if any) to confirm tables/indexes align with access patterns. - [ ] Document schema in `docs/` (ER diagram, migration history). 2. **Connection Management** - [ ] Validate pool settings (`max_open`, `max_idle`, `conn max lifetime`) and expose via config. - [ ] Implement health checks and failover for primary/replica setups. 3. **Transaction Integrity** - [ ] Ensure critical writes use transactions with rollback on error. - [ ] Add tests for idempotent persistence (e.g., duplicate opportunities). 4. **Performance & Monitoring** - [ ] Instrument slow query logging and Prometheus metrics. - [ ] Run load tests to ensure queue/execution writes keep up under peak load. 5. **Docs & Runbooks** - [ ] Update deployment docs with connection strings, maintenance tasks, backup/restore procedures. ## References - `pkg/database/database.go` - `pkg/database/database_test.go` - `docs/6_operations/DEPLOYMENT_GUIDE.md`