Behflow uses PostgreSQL as its database. The database schema includes tables for users, tasks, chat sessions, messages, and automated processes.
When running Behflow with Docker Compose, the database is automatically initialized on first startup:
- PostgreSQL container starts
- Migration scripts in
infra/migrations/are executed automatically - All tables, indexes, and default data are created
# From the project root
cd infra
docker compose up -dThe database will be ready with all tables created!
- Host: localhost
- Port: 15432
- Database: behflow_dev
- Username: behflow
- Password: admin
psql -h localhost -p 15432 -U behflow -d behflow_dev- Host: infra-db (container name)
- Port: 5432
- Database: behflow_dev
- Username: behflow
- Password: admin
- users - User accounts and authentication
- tasks - User tasks with priorities and statuses
- chat_sessions - Chat conversation sessions
- chat_messages - Individual chat messages
- automated_processes - Scheduled/automated processes configuration
- automated_process_executions - Execution history and results
priority_enum: low, medium, highstatus_enum: pending, in_progress, completed, cancelledtrigger_type_enum: manual, time_based, event_basedprocess_status_enum: pending, running, completed, failed, disabled
Migration files are located in infra/migrations/ and executed in alphabetical order:
- 000_init_database.sql - Creates all tables, types, and indexes
- 001_add_automated_processes.sql - Additional automated process configurations (legacy, now included in 000)
To completely reset the database and start fresh:
# Stop all services
docker compose down
# Remove the database volume
docker volume rm infra_db_data
# Start services (database will be recreated)
docker compose up -dConnect to the database and verify tables:
# Connect to database
docker exec -it infra-db psql -U behflow -d behflow_dev
# List all tables
\dt
# List all types
\dT
# Check automated processes
SELECT process_id, name, trigger_type, is_enabled FROM automated_processes;
# Exit
\qIf you need to run migrations manually:
# Copy migration file into container
docker cp infra/migrations/000_init_database.sql infra-db:/tmp/
# Execute migration
docker exec -it infra-db psql -U behflow -d behflow_dev -f /tmp/000_init_database.sql- PostgreSQL 15+ installed locally
- Database created:
behflow_dev
- Create database:
createdb -U postgres behflow_dev- Run migrations:
psql -U postgres -d behflow_dev -f infra/migrations/000_init_database.sql- Update environment variable:
export DATABASE_URL="postgresql://postgres:your_password@localhost:5432/behflow_dev"- Run backend:
cd src/backend
uvicorn app.main:app --reloadThis means tables haven't been created. Solutions:
- For Docker: Reset the database volume (see above)
- For Local: Run the migration files manually
Check:
- PostgreSQL is running:
docker ps(for Docker) orpg_isready(for local) - Correct credentials in
DATABASE_URL - Firewall/port settings
Check the PostgreSQL logs:
docker logs infra-dbThe following default data is automatically created:
- reschedule_remaining_tasks: Reschedules incomplete tasks daily at 7:30 AM (Asia/Tehran timezone)
# Using Docker
docker exec infra-db pg_dump -U behflow behflow_dev > backup.sql
# Local
pg_dump -U postgres behflow_dev > backup.sql# Using Docker
docker exec -i infra-db psql -U behflow behflow_dev < backup.sql
# Local
psql -U postgres behflow_dev < backup.sqlWhen adding new tables or columns:
- Create a new migration file:
infra/migrations/00X_description.sql - Number it sequentially (002, 003, etc.)
- For Docker: Restart the database container
- For Local: Run the migration manually
- Change default passwords in
docker-compose.yml - Use environment variables for sensitive data
- Restrict database port exposure
- Enable SSL/TLS connections
- Regular backups