Update database schema and configuration for Crypto Trading Bot Platform
- Added new SQLAlchemy models in `database/models.py` for market data, trades, bots, signals, and performance tracking. - Updated `docker-compose.yml` to use TimescaleDB for PostgreSQL and configured shared preload libraries. - Created new schema files: `schema.sql` for the complete database setup and `schema_clean.sql` for a simplified version without hypertables. - Updated documentation in `setup.md` to reflect changes in database initialization and service setup.
This commit is contained in:
@@ -70,17 +70,18 @@ REDIS_PASSWORD=redis987secure
|
||||
|
||||
### 1. Start Database Services
|
||||
|
||||
Start PostgreSQL and Redis using Docker Compose:
|
||||
Start PostgreSQL with TimescaleDB and Redis using Docker Compose:
|
||||
|
||||
```powershell
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
This will:
|
||||
- Create a PostgreSQL database on port `5434`
|
||||
- Create a PostgreSQL database with TimescaleDB extension on port `5434`
|
||||
- Create a Redis instance on port `6379`
|
||||
- Set up persistent volumes for data storage
|
||||
- Configure password authentication
|
||||
- **Automatically initialize the database schema** using scripts in `database/init/`
|
||||
|
||||
### 2. Verify Services are Running
|
||||
|
||||
@@ -91,20 +92,41 @@ docker-compose ps
|
||||
|
||||
Expected output:
|
||||
```
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
dashboard_postgres postgres:15-alpine "docker-entrypoint.s…" postgres X minutes ago Up X minutes (healthy) 0.0.0.0:5434->5432/tcp
|
||||
dashboard_redis redis:7-alpine "docker-entrypoint.s…" redis X minutes ago Up X minutes (healthy) 0.0.0.0:6379->6379/tcp
|
||||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||||
dashboard_postgres timescale/timescaledb:latest-pg15 "docker-entrypoint.s…" postgres X minutes ago Up X minutes (healthy) 0.0.0.0:5434->5432/tcp
|
||||
dashboard_redis redis:7-alpine "docker-entrypoint.s…" redis X minutes ago Up X minutes (healthy) 0.0.0.0:6379->6379/tcp
|
||||
```
|
||||
|
||||
### 3. Test Database Connections
|
||||
### 3. Verify Database Schema
|
||||
|
||||
Check if tables were created successfully:
|
||||
```powershell
|
||||
docker exec dashboard_postgres psql -U dashboard -d dashboard -c "\dt"
|
||||
```
|
||||
|
||||
Expected output should show tables: `bots`, `bot_performance`, `market_data`, `signals`, `supported_exchanges`, `supported_timeframes`, `trades`
|
||||
|
||||
### 4. Manual Schema Application (If Needed)
|
||||
|
||||
If the automatic initialization didn't work, you can manually apply the schema:
|
||||
|
||||
```powershell
|
||||
# Apply the complete schema
|
||||
Get-Content database/schema.sql | docker exec -i dashboard_postgres psql -U dashboard -d dashboard
|
||||
|
||||
# Or apply the clean version (without TimescaleDB hypertables)
|
||||
Get-Content database/schema_clean.sql | docker exec -i dashboard_postgres psql -U dashboard -d dashboard
|
||||
```
|
||||
|
||||
### 5. Test Database Connections
|
||||
|
||||
Test PostgreSQL connection:
|
||||
```powershell
|
||||
# Test port accessibility
|
||||
Test-NetConnection -ComputerName localhost -Port 5434
|
||||
|
||||
# Test database connection (from inside container)
|
||||
docker exec dashboard_postgres psql -h localhost -p 5432 -U dashboard -d dashboard -c "SELECT version();"
|
||||
# Test database connection and check schema
|
||||
docker exec dashboard_postgres psql -U dashboard -d dashboard -c "SELECT COUNT(*) FROM bots;"
|
||||
```
|
||||
|
||||
Test Redis connection:
|
||||
@@ -140,11 +162,16 @@ uv run <command>
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
### 3. Initialize Database Schema
|
||||
### 3. Verify Database Schema (Optional)
|
||||
|
||||
The database schema is automatically initialized when Docker containers start. You can verify it's working:
|
||||
|
||||
```powershell
|
||||
# Run database migrations (when implemented)
|
||||
uv run python scripts/init_db.py
|
||||
# Check if all tables exist
|
||||
docker exec dashboard_postgres psql -U dashboard -d dashboard -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name;"
|
||||
|
||||
# Verify sample data was inserted
|
||||
docker exec dashboard_postgres psql -U dashboard -d dashboard -c "SELECT * FROM supported_timeframes;"
|
||||
```
|
||||
|
||||
## Running the Application
|
||||
@@ -320,7 +347,33 @@ uv run python test_connection.py
|
||||
- Reset database: `docker-compose down -v && docker-compose up -d`
|
||||
- Wait for database initialization (30-60 seconds)
|
||||
|
||||
#### 4. Python Dependencies Issues
|
||||
#### 4. Database Schema Not Created
|
||||
|
||||
**Error**: Tables don't exist or `\dt` shows no tables
|
||||
|
||||
**Solution**:
|
||||
```powershell
|
||||
# Check initialization logs
|
||||
docker-compose logs postgres
|
||||
|
||||
# Manually apply schema if needed
|
||||
Get-Content database/schema_clean.sql | docker exec -i dashboard_postgres psql -U dashboard -d dashboard
|
||||
|
||||
# Verify tables were created
|
||||
docker exec dashboard_postgres psql -U dashboard -d dashboard -c "\dt"
|
||||
```
|
||||
|
||||
#### 5. TimescaleDB Extension Issues
|
||||
|
||||
**Error**: `extension "timescaledb" is not available`
|
||||
|
||||
**Solution**:
|
||||
- Ensure using TimescaleDB image: `timescale/timescaledb:latest-pg15`
|
||||
- Check docker-compose.yml has correct image
|
||||
- Restart containers: `docker-compose down && docker-compose up -d`
|
||||
- Use clean schema if needed: `database/schema_clean.sql`
|
||||
|
||||
#### 6. Python Dependencies Issues
|
||||
|
||||
**Error**: Package installation failures
|
||||
|
||||
|
||||
Reference in New Issue
Block a user