Production database is the source of truth.
- ✅ Production database has customer data (4 users, 48 portfolio items)
- ❌ DO NOT overwrite production with local data
- ❌ DO NOT migrate local database to production
✅ Verified Working:
- Database: PostgreSQL
- Customer accounts: 4 users
- Your account: ssfskype@gmail.com (ID: 1, Active)
- Portfolio items: 48 items
- Connection: Working
Production backend MUST use these settings:
# In production .env file or docker-compose environment
ENVIRONMENT=production
DATABASE_URL=postgresql+psycopg://${POSTGRES_USER:-crypto}:${POSTGRES_PASSWORD:-crypto_pass}@postgres:${DB_SERVER_PORT:-5432}/${POSTGRES_DB:-crypto_ai_agent} # DB_SERVER_PORT from database-server/.envImportant points:
- Hostname is 'postgres' (Docker network hostname, NOT 'localhost')
- ENVIRONMENT=production (ensures PostgreSQL is used)
- Network must be 'nginx-network' (to reach 'postgres' hostname)
Production backend container configuration:
# docker-compose.blue.yml or docker-compose.green.yml
services:
backend:
environment:
- DATABASE_URL=postgresql+psycopg://${POSTGRES_USER:-crypto}:${POSTGRES_PASSWORD:-crypto_pass}@postgres:${DB_SERVER_PORT:-5432}/${POSTGRES_DB:-crypto_ai_agent} # DB_SERVER_PORT from database-server/.env
- ENVIRONMENT=production
networks:
- default
- nginx-network # CRITICAL: Must be on this networkNetwork requirement:
- Backend container MUST be on
nginx-network - This allows backend to reach
postgreshostname (shared infrastructure)
Production database runs as shared infrastructure:
# docker-compose.infrastructure.yml
services:
postgres:
container_name: crypto-ai-postgres
networks:
- nginx-network # Shared networkBoth blue and green backends connect to the SAME production database.
If production login fails with "Could not validate credentials":
# From production server
cd /path/to/crypto-ai-agent
python3 scripts/check_production_database.pyShould show:
- ✅ Connection successful
- ✅ 4 customer accounts
- ✅ Your account found
# Check backend container is on nginx-network
docker inspect crypto-ai-backend-blue | grep -A 10 Networks
# Should show: nginx-network# Check backend container environment
docker exec crypto-ai-backend-blue env | grep -E "DATABASE_URL|ENVIRONMENT"
# Should show:
# ENVIRONMENT=production
# DATABASE_URL=postgresql+psycopg://crypto:***@postgres:5432/crypto_ai_agentCritical: Hostname must be postgres (not localhost or IP)
# Test connection from inside backend container
docker exec crypto-ai-backend-blue python3 -c "
from app.utils.db import connect_with_retry
conn = connect_with_retry()
cur = conn.cursor()
cur.execute('SELECT COUNT(*) FROM users')
print(f'Users: {cur.fetchone()[0]}')
"# Check backend logs for database errors
docker logs crypto-ai-backend-blue | grep -i "database\|connection\|error"Look for:
- ✅ "Database connection successful"
- ✅ "Database schema exists with X users"
- ❌ "Database connection failed"
- ❌ "Could not connect to database"
# Check backend health endpoint
curl https://crypto-ai-agent.alfares.cz/api/health
# Should show:
# {
# "status": "healthy",
# "database_connected": true,
# "database_has_data": true,
# "user_count": 4
# }Symptom: Backend cannot connect to database
Solution:
# Update DATABASE_URL in .env or docker-compose
DATABASE_URL=postgresql+psycopg://user:pass@postgres:${DB_SERVER_PORT:-5432}/db # DB_SERVER_PORT from database-server/.env
# NOT: @localhost:5432/dbSymptom: Cannot resolve 'postgres' hostname
Solution:
# docker-compose.blue.yml
services:
backend:
networks:
- default
- nginx-network # Add thisSymptom: Connects to wrong/empty database
Solution:
- Verify DATABASE_URL matches production database
- Check POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB match infrastructure
Symptom: Backend cannot connect to PostgreSQL database
Solution:
# Set in .env or docker-compose
ENVIRONMENT=productionBefore deploying, verify:
- Production database has customer data (4+ users)
- Backend DATABASE_URL uses 'postgres' hostname
- Backend ENVIRONMENT=production
- Backend container on nginx-network
- Shared infrastructure (postgres) running
- Health endpoint shows database_has_data=true
- Login endpoint can query users table
- check_production_database.py - Verify production database has data
- verify_production_connection.py - Verify backend can connect to production DB
- verify_customer_data.py - List all customer accounts
DO NOT USE:
- ❌ migrate_to_production_db.py (DELETED - never migrate from local)
✅ Production database HAS customer data ✅ Production backend MUST connect to production database ✅ Production backend MUST use 'postgres' hostname (Docker network) ✅ Production backend MUST be on nginx-network
If login fails, the issue is configuration (wrong DATABASE_URL, wrong network, etc.), NOT missing data.