# Phase 4: Policy Module Conversion **Sprint:** 5 **Duration:** 1 sprint **Status:** TODO **Dependencies:** Phase 0 (Foundations) --- ## Objectives 1. Create `StellaOps.Policy.Storage.Postgres` project 2. Implement Policy schema in PostgreSQL 3. Handle policy pack versioning correctly 4. Implement risk profiles with version history --- ## Deliverables | Deliverable | Acceptance Criteria | |-------------|---------------------| | Policy schema | All tables created with indexes | | Repository implementations | All 4+ interfaces implemented | | Version management | Pack versioning working correctly | | Integration tests | 100% coverage of CRUD operations | --- ## Schema Reference See [SPECIFICATION.md](../SPECIFICATION.md) Section 5.6 for complete Policy schema. **Tables:** - `policy.packs` - `policy.pack_versions` - `policy.rules` - `policy.risk_profiles` - `policy.evaluation_runs` - `policy.explanations` - `policy.exceptions` - `policy.audit` --- ## Task Breakdown ### T4.1: Create Policy.Storage.Postgres Project **Status:** TODO **Estimate:** 0.5 days --- ### T4.2: Implement Schema Migrations **Status:** TODO **Estimate:** 1 day --- ### T4.3: Implement Pack Repository **Status:** TODO **Estimate:** 1 day **Subtasks:** - [ ] Implement CRUD for packs - [ ] Implement version management - [ ] Handle active version promotion - [ ] Write integration tests --- ### T4.4: Implement Risk Profile Repository **Status:** TODO **Estimate:** 1 day **Subtasks:** - [ ] Implement CRUD operations - [ ] Handle version history - [ ] Implement GetVersionAsync - [ ] Implement ListVersionsAsync - [ ] Write integration tests --- ### T4.5: Implement Remaining Repositories **Status:** TODO **Estimate:** 1.5 days **Subtasks:** - [ ] Implement Evaluation Run repository - [ ] Implement Explanation repository - [ ] Implement Exception repository - [ ] Implement Audit repository - [ ] Write integration tests --- ### T4.6: Add Configuration Switch **Status:** TODO **Estimate:** 0.5 days --- ### T4.7: Run Verification Tests **Status:** TODO **Estimate:** 1 day --- ### T4.8: Migrate Active Policy Packs **Status:** TODO **Estimate:** 0.5 days **Subtasks:** - [ ] Export active packs from MongoDB - [ ] Import to PostgreSQL - [ ] Verify version numbers - [ ] Verify active version settings --- ### T4.9: Switch to PostgreSQL-Only **Status:** TODO **Estimate:** 0.5 days --- ## Exit Criteria - [ ] All repository interfaces implemented - [ ] Pack versioning working correctly - [ ] All integration tests pass - [ ] Policy running on PostgreSQL in production --- *Phase Version: 1.0.0* *Last Updated: 2025-11-28*