Overview
Support Bot uses three database systems:- PostgreSQL - Main application database (port 5434)
- pgvector - Vector embeddings storage (port 5433)
- Qdrant - Vector search engine (ports 6333, 6334)
Database Services
Main Database (PostgreSQL)
Stores application data including:- User accounts and authentication
- Chat conversations and messages
- LangGraph checkpoints
- Application metadata
Vector Database (pgvector)
Stores vector embeddings for semantic search and retrieval:- Document embeddings
- Sentence transformers output
- RAG (Retrieval-Augmented Generation) data
Qdrant
Vector similarity search engine for:- Fast nearest neighbor search
- Document retrieval
- Semantic search operations
Database Initialization
First-Time Setup
Verify databases are running
postgres-db(port 5434)vector-db(port 5433)qdrant-db(ports 6333, 6334)
Run initial migrations
Navigate to the Alembic directory and upgrade to the latest schema:This creates all necessary tables and indexes.
Production Deployment
In production, the Docker container automatically runs migrations on startup:Alembic Migrations
Alembic manages database schema versions and changes.Migration Commands
Upgrade to latest schema
Upgrade to latest schema
Check current migration
Check current migration
View migration history
View migration history
Downgrade to previous version
Downgrade to previous version
Creating New Migrations
When you modify database models insrc/api/db/models.py, create a migration:
Generate migration
Review generated migration
Check the generated file in Verify the changes are correct before applying.
src/api/db/versions/:Migration Best Practices
Always review auto-generated migrations
Always review auto-generated migrations
Alembic’s autogenerate is powerful but not perfect. Review:
- Column types and constraints
- Index definitions
- Data migration needs
- Downgrade logic
Test migrations on a copy of production data
Test migrations on a copy of production data
Write descriptive migration messages
Write descriptive migration messages
Use clear, action-oriented descriptions:
- Good:
"add email verification to users" - Good:
"create conversations table with indexes" - Bad:
"update db" - Bad:
"changes"
Keep migrations small and focused
Keep migrations small and focused
One logical change per migration:
- Add a table
- Modify a column
- Create an index
Database Management
Using Adminer
Adminer provides a web UI for database management (development only):- Open http://localhost:8080
- Login credentials:
- System: PostgreSQL
- Server:
db:5432(for main DB) orvector_db:5432 - Username:
postgres - Password:
admin - Database:
bot_dborvector_db
Using psql
Connect directly via command line:Common SQL Operations
- List Tables
- Describe Table
- Check Connections
- Database Size
Backup and Restore
Backup Database
- Using pg_dump
- Using Docker volumes
Restore Database
- From SQL dump
- From volume backup
Troubleshooting
Migration Errors
'current' revision not found
'current' revision not found
Initialize Alembic:
Constraint violation during migration
Constraint violation during migration
- Check existing data compatibility
- Add data migration step:
Multiple heads detected
Multiple heads detected
Merge migration branches:
Connection Issues
Connection refused
Connection refused
- Verify container is running:
- Check port mapping:
- Test connection:
Authentication failed
Authentication failed
Check credentials in environment variables:Ensure they match Docker Compose configuration.
Next Steps
Environment Variables
Configure database connection strings
Docker Deployment
Deploy with Docker Compose