157 lines
3.2 KiB
Markdown
157 lines
3.2 KiB
Markdown
# Phase 8: Platform Service Simplification
|
|
|
|
## Agent Assignment
|
|
**Primary Agent:** platform-agent
|
|
**Duration:** 35-45 minutes
|
|
|
|
## Prerequisites
|
|
- Phase 1 (Docker Compose) must be complete
|
|
|
|
## Objectives
|
|
1. Remove MSSQL database dependency
|
|
2. Remove ETL container and pipeline
|
|
3. Update to use mvp-postgres and mvp-redis
|
|
4. Load VPIC data at startup (not weekly ETL)
|
|
5. Simplify to single container
|
|
|
|
## Step-by-Step Instructions
|
|
|
|
### Step 1: Update Platform Service Config
|
|
Modify `mvp-platform-services/vehicles/config.py`:
|
|
|
|
```python
|
|
# Update database connection
|
|
DATABASE_URL = os.getenv(
|
|
'DATABASE_URL',
|
|
'postgresql://postgres:password@mvp-postgres:5432/motovaultpro'
|
|
)
|
|
|
|
# Update Redis connection
|
|
REDIS_URL = os.getenv(
|
|
'REDIS_URL',
|
|
'redis://mvp-redis:6379'
|
|
)
|
|
|
|
# Use vehicles_platform schema for isolation
|
|
SCHEMA = 'vehicles_platform'
|
|
```
|
|
|
|
### Step 2: Update requirements.txt
|
|
Remove MSSQL dependencies:
|
|
```
|
|
# REMOVE:
|
|
# pymssql
|
|
# pyodbc
|
|
|
|
# KEEP:
|
|
psycopg2-binary
|
|
redis
|
|
fastapi
|
|
uvicorn
|
|
```
|
|
|
|
### Step 3: Remove ETL Code
|
|
```bash
|
|
cd mvp-platform-services/vehicles/
|
|
|
|
# Remove ETL scripts
|
|
rm -rf etl/
|
|
|
|
# Remove MSSQL migration scripts
|
|
rm -rf migrations/mssql/
|
|
```
|
|
|
|
### Step 4: Create Startup Data Loader
|
|
Create `mvp-platform-services/vehicles/startup_loader.py`:
|
|
|
|
```python
|
|
"""Load VPIC data at service startup"""
|
|
import asyncio
|
|
from database import get_db
|
|
from vpic_client import VPICClient
|
|
|
|
async def load_initial_data():
|
|
"""Load vehicle data from VPIC API at startup"""
|
|
db = await get_db()
|
|
vpic = VPICClient()
|
|
|
|
# Check if data already loaded
|
|
result = await db.fetch_one("SELECT COUNT(*) FROM vehicles_platform.makes")
|
|
if result[0] > 0:
|
|
print("Data already loaded, skipping...")
|
|
return
|
|
|
|
# Load makes, models, etc. from VPIC
|
|
print("Loading initial vehicle data...")
|
|
# Implementation here...
|
|
```
|
|
|
|
### Step 5: Update main.py
|
|
```python
|
|
from startup_loader import load_initial_data
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
"""Run on service startup"""
|
|
await load_initial_data()
|
|
```
|
|
|
|
### Step 6: Update Dockerfile
|
|
```dockerfile
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
COPY . .
|
|
|
|
# No ETL dependencies needed
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
```
|
|
|
|
### Step 7: Rebuild and Test
|
|
```bash
|
|
# Rebuild platform service
|
|
docker compose build mvp-platform
|
|
|
|
# Restart
|
|
docker compose up -d mvp-platform
|
|
|
|
# Check logs
|
|
docker compose logs mvp-platform
|
|
|
|
# Test API
|
|
curl http://localhost:8000/health
|
|
curl http://localhost:8000/vehicles/makes?year=2024
|
|
```
|
|
|
|
## Validation Criteria
|
|
- [ ] No MSSQL dependencies in requirements.txt
|
|
- [ ] No ETL code remains
|
|
- [ ] Uses mvp-postgres for database
|
|
- [ ] Uses mvp-redis for cache
|
|
- [ ] Service starts successfully
|
|
- [ ] API endpoints work
|
|
- [ ] VIN decode functional
|
|
|
|
**Validation Commands:**
|
|
```bash
|
|
grep -r "mssql\|pymssql\|pyodbc" mvp-platform-services/vehicles/
|
|
# Expected: 0 results
|
|
|
|
docker compose exec mvp-platform python -c "import psycopg2; print('OK')"
|
|
# Expected: OK
|
|
|
|
curl http://localhost:8000/vehicles/makes?year=2024
|
|
# Expected: JSON response with makes
|
|
```
|
|
|
|
## Update EXECUTION-STATE.json
|
|
```json
|
|
{
|
|
"phases": {"8": {"status": "completed", "validation_passed": true}}
|
|
}
|
|
```
|