3.2 KiB
3.2 KiB
Phase 8: Platform Service Simplification
Agent Assignment
Primary Agent: platform-agent Duration: 35-45 minutes
Prerequisites
- Phase 1 (Docker Compose) must be complete
Objectives
- Remove MSSQL database dependency
- Remove ETL container and pipeline
- Update to use mvp-postgres and mvp-redis
- Load VPIC data at startup (not weekly ETL)
- Simplify to single container
Step-by-Step Instructions
Step 1: Update Platform Service Config
Modify mvp-platform-services/vehicles/config.py:
# 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
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:
"""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
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
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
# 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:
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
{
"phases": {"8": {"status": "completed", "validation_passed": true}}
}