PostgreSQL database with REST API for YouTube-related data management.
- Docker Desktop installed and running
- Python 3.10+ installed
- Git (optional)
# Navigate to project
cd C:\Projects\database_youtube
# Copy environment file and edit with your settings (if .env doesn't exist)
# copy .env.example .env
# Edit .env and set POSTGRES_PASSWORD to a secure password
# Start all services (PostgreSQL, API, Backup)
docker-compose -f docker/docker-compose.yml up -d
# Wait for services to be ready (check logs)
docker-compose -f docker/docker-compose.yml logs -f
# Verify API is running
curl http://localhost:8000/healthNote: The API now runs in Docker and doesn't require a terminal window to stay open. It will automatically restart if it crashes.
- Database:
http://localhost:5432(PostgreSQL) - API:
http://localhost:8000(FastAPI) - API Docs:
http://localhost:8000/docs(Swagger UI) - Health Check:
http://localhost:8000/health
database_youtube/
├── docker/ # Docker configuration
├── api/ # FastAPI application
├── scripts/ # Utility scripts (backup, restore, etc.)
├── data/ # Database data and backups
└── tests/ # Unit tests
GET /health- API health checkGET /api/v1/health/- API health check (v1)GET /api/v1/health/db- Database connection check
Note: The API currently provides only health endpoints. YouTube-related tables (videos, video_labels, transcripts, etc.) are managed by other processes and accessed directly via the database.
python scripts/backup.pypython scripts/restore.py data/backups/daily/backup_20241205.sqlBackups run automatically daily at 2:00 AM (configurable in .env).
# Run API tests
python test/test_api.py# Create migration
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade headAll configuration is in .env file. See .env.example for available options.
- Never commit
.envfile to git - Use strong database passwords
- Consider adding API authentication for production
- Restrict network access to database port
The project includes three Docker services:
- postgres - PostgreSQL database (port 5432)
- api - FastAPI application (port 8000)
- backup - Automated backup service (runs daily at 2:00 AM)
All services are configured in docker/docker-compose.yml and start automatically with docker-compose up -d.
- Check if port 5432 is already in use
- Check Docker logs:
docker-compose -f docker/docker-compose.yml logs postgres - Verify Docker Desktop is running
- Check API logs:
docker logs database-youtube-api - Verify database is healthy:
docker ps(should show "healthy" status) - Check API can connect to database:
docker exec database-youtube-api python -c "from api.config import settings; print(settings.database_url)"
- Ensure containers are running:
docker ps - Check POSTGRES_HOST and POSTGRES_PORT in .env or docker-compose.yml
- Verify firewall settings
- For API: Ensure it's using
postgresas hostname (Docker service name), notlocalhost
For issues or questions, refer to database_plan.md for detailed architecture and design decisions.