feat: add PostgreSQL to production setup (v9b)
Prepares production for SQLite → PostgreSQL migration: - Add postgres service (mitai-db, port 5432) - Add DB environment variables to backend - Backend depends on postgres health check - Uses startup.sh for automatic migration Migration strategy: 1. SQLite data in /app/data/bodytrack.db is preserved (volume mounted) 2. On first start with empty PostgreSQL: automatic migration 3. Migration is safe: checks if profiles table is empty before migrating 4. After migration: all new data goes to PostgreSQL IMPORTANT: Set DB_PASSWORD in .env before deploying! Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d2c578de83
commit
39a7b1be78
|
|
@ -1,22 +1,55 @@
|
|||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: mitai-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: mitai_prod
|
||||
POSTGRES_USER: mitai_prod
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD:-change_me_in_production}
|
||||
volumes:
|
||||
- mitai_postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U mitai_prod"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
backend:
|
||||
build: ./backend
|
||||
container_name: mitai-api
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8002:8000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- bodytrack_bodytrack-data:/app/data
|
||||
- bodytrack_bodytrack-photos:/app/photos
|
||||
environment:
|
||||
# Database
|
||||
- DB_HOST=postgres
|
||||
- DB_PORT=5432
|
||||
- DB_NAME=mitai_prod
|
||||
- DB_USER=mitai_prod
|
||||
- DB_PASSWORD=${DB_PASSWORD:-change_me_in_production}
|
||||
|
||||
# AI
|
||||
- OPENROUTER_API_KEY=${OPENROUTER_API_KEY}
|
||||
- OPENROUTER_MODEL=${OPENROUTER_MODEL:-anthropic/claude-sonnet-4}
|
||||
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
|
||||
|
||||
# Email
|
||||
- SMTP_HOST=${SMTP_HOST}
|
||||
- SMTP_PORT=${SMTP_PORT:-587}
|
||||
- SMTP_USER=${SMTP_USER}
|
||||
- SMTP_PASS=${SMTP_PASS}
|
||||
- SMTP_FROM=${SMTP_FROM}
|
||||
|
||||
# App
|
||||
- APP_URL=${APP_URL}
|
||||
- DATA_DIR=/app/data
|
||||
- PHOTOS_DIR=/app/photos
|
||||
|
|
@ -33,6 +66,7 @@ services:
|
|||
- backend
|
||||
|
||||
volumes:
|
||||
mitai_postgres_data:
|
||||
bodytrack_bodytrack-data:
|
||||
external: true
|
||||
bodytrack_bodytrack-photos:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user