DanteGPU Platform - Database Documentation
Overview
This directory contains all database schemas, migrations, and setup scripts for the DanteGPU decentralized GPU rental platform.
Database Architecture
The platform uses PostgreSQL 15+ with the following databases:
dante_core- Main application database (default)dante_auth- Authentication and user managementdante_billing- Payment and billing recordsdante_registry- Provider and GPU registrydante_scheduler- Job scheduling and orchestration
Migration Files
Core Schema Migrations
-
001_initial_schema.sql (168 lines)
- Users table
- GPU providers table
- GPU models table
- GPU instances table
- GPU rentals table
- Payment transactions table
- GPU metrics table
- User sessions table
- Notifications table
- Basic indexes and triggers
-
002_sample_data.sql (70 lines)
- Sample GPU providers
- Sample GPU models (RTX 4090, A100, RTX 3080, H100)
- Sample GPU instances
- Sample users
- Sample rentals and transactions
Blockchain Integration (Migration 003)
003_blockchain_tables.sql (300 lines)
Tables:
wallets- dGPU token wallet managementblockchain_transactions- Solana transaction trackingrental_sessions- Minute-based billing sessionsusage_records- GPU usage meteringescrow_transactions- Secure payment escrowplatform_fees- Platform fee collection (5%)provider_payouts- Provider earnings distribution
Functions:
wallet_available_balance(wallet_id)- Calculate available balancelock_wallet_funds(wallet_id, amount)- Lock funds for escrowrelease_wallet_funds(wallet_id, amount)- Release locked funds
Job Execution (Migration 004)
004_jobs_and_execution.sql (300 lines)
Tables:
jobs- GPU job management with Docker orchestrationjob_logs- Streaming logs (partitioned by month)job_metrics- Performance metrics (partitioned by month)job_files- Input/output file managementjob_checkpoints- Checkpoint management for long-running jobsjob_dependencies- Workflow dependenciesjob_events- Audit trail for job events
Functions:
get_job_status_summary(user_id)- Get job statisticscalculate_job_duration(job_id)- Calculate job runtimecan_job_start(job_id)- Check if dependencies are met
Authentication & Security (Migration 005)
005_auth_and_security.sql (300 lines)
Tables:
api_keys- API key management with scopes and rate limitingapi_key_usage- API usage trackingaudit_logs- System-wide audit logging (partitioned)security_events- Threat detection and security monitoringuser_roles- Role assignmentspermissions- Permission definitionsrole_permissions- Role-permission mappinguser_permissions- User-specific permission overrideslogin_attempts- Login attempt trackingpassword_reset_tokens- Password reset flowemail_verification_tokens- Email verificationtwo_factor_auth- 2FA (TOTP, SMS, email)active_sessions- Session management
Functions:
user_has_permission(user_id, permission_name)- Check user permissions
Provider & GPU Registry (Migration 006)
006_providers_and_gpu_registry.sql (300 lines)
Tables:
providers- Enhanced provider managementgpu_capabilities- Detailed GPU specificationsgpu_availability_schedule- Availability schedulinggpu_reservations- GPU reservation systemprovider_reviews- Provider ratings and reviewsprovider_payout_requests- Payout request management
Functions:
update_provider_rating(provider_id)- Recalculate provider ratingis_gpu_available(gpu_id, start_time, end_time)- Check availability
Performance Optimization (Migration 007)
007_additional_indexes.sql (300 lines)
Features:
- Composite indexes for common query patterns
- Partial indexes for filtered queries
- GIN indexes for JSONB columns
- Full-text search with tsvector
- Covering indexes for index-only scans
- Statistics optimization
Running Migrations
Prerequisites
- PostgreSQL 15 or higher
psqlcommand-line tool- Database credentials configured in
.envfile
Environment Variables
Create a .env file in the project root:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=dante_core
DB_USER=dante_user
DB_PASSWORD=your_secure_password
Run All Migrations
./database/run_migrations.sh run
Check Migration Status
./database/run_migrations.sh status
Migration Tracking
Migrations are tracked in the schema_migrations table:
SELECT * FROM schema_migrations ORDER BY id;
Each migration records:
- Version number
- Migration name
- Execution timestamp
- Execution time (ms)
- File checksum
Database Schema Overview
Key Tables and Relationships
users
├── wallets (1:N)
├── rental_sessions (1:N)
├── jobs (1:N)
├── api_keys (1:N)
└── user_sessions (1:N)
providers
├── gpu_capabilities (1:N)
├── rental_sessions (1:N)
└── provider_reviews (1:N)
gpu_capabilities
├── gpu_reservations (1:N)
└── jobs (1:N)
rental_sessions
├── usage_records (1:N)
├── escrow_transactions (1:N)
└── blockchain_transactions (1:N)
jobs
├── job_logs (1:N)
├── job_metrics (1:N)
├── job_files (1:N)
└── job_checkpoints (1:N)
Blockchain Integration
The platform integrates with Solana blockchain for payments:
- dGPU Token:
7xUV6YR3rZMfExPqZiovQSUxpnHxr2KJJqFg1bFrpump - Network: Solana mainnet-beta
- Escrow: Smart contract-based escrow for secure payments
- Platform Fee: 5% on all transactions
Billing Model
- Minute-based billing: Usage tracked per minute
- Escrow system: Funds locked before rental starts
- Automatic billing: Deducted from escrow every minute
- Provider payout: Automatic after rental completion
- Platform fee: 5% collected on each transaction
Performance Considerations
Partitioning
Large tables are partitioned by time:
job_logs_partitioned- Partitioned by monthjob_metrics_partitioned- Partitioned by monthaudit_logs_partitioned- Partitioned by month
Indexing Strategy
- Composite indexes for multi-column queries
- Partial indexes for filtered queries (e.g., WHERE status = 'active')
- GIN indexes for JSONB and full-text search
- Covering indexes for index-only scans
Query Optimization
- Statistics targets set to 1000 for frequently queried columns
- ANALYZE run on all tables after migration
- Proper foreign key constraints for referential integrity
- CHECK constraints for data validation
Backup and Recovery
Backup Script (Recommended)
#!/bin/bash
BACKUP_DIR="/var/backups/dantegpu"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
pg_dump -h localhost -U dante_user -d dante_core \
-F c -b -v -f "$BACKUP_DIR/dante_core_$TIMESTAMP.backup"
Restore from Backup
pg_restore -h localhost -U dante_user -d dante_core \
-v "$BACKUP_DIR/dante_core_20240101_120000.backup"
Security Best Practices
- Never commit
.envfiles with real credentials - Use strong passwords for database users
- Enable SSL/TLS for database connections in production
- Restrict database access to application servers only
- Regular backups with point-in-time recovery
- Audit logging enabled for all sensitive operations
- Encryption at rest for sensitive data
Monitoring
Key Metrics to Monitor
- Connection pool utilization
- Query execution time
- Index usage statistics
- Table bloat
- Replication lag (if using replication)
- Disk space usage
Useful Queries
-- Check table sizes
SELECT
schemaname,
tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
-- Check index usage
SELECT
schemaname,
tablename,
indexname,
idx_scan,
idx_tup_read,
idx_tup_fetch
FROM pg_stat_user_indexes
ORDER BY idx_scan DESC;
-- Check slow queries
SELECT
query,
calls,
total_time,
mean_time,
max_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 20;
Troubleshooting
Migration Failed
- Check PostgreSQL logs:
tail -f /var/log/postgresql/postgresql-15-main.log - Verify database connection:
psql -h localhost -U dante_user -d dante_core - Check migration file syntax
- Ensure all dependencies are met
Performance Issues
- Run ANALYZE:
ANALYZE; - Check for missing indexes
- Review slow query log
- Consider partitioning large tables
- Optimize queries with EXPLAIN ANALYZE
Development
Adding New Migrations
- Create new file:
database/migrations/008_your_migration.sql - Follow naming convention:
{number}_{description}.sql - Include rollback logic in comments
- Test on development database first
- Run migration:
./database/run_migrations.sh run
Testing Migrations
# Create test database
createdb dante_test
# Run migrations
DB_NAME=dante_test ./database/run_migrations.sh run
# Run tests
# ... your test commands ...
# Drop test database
dropdb dante_test
Support
For issues or questions:
- GitHub Issues: https://github.com/dante-gpu/dantegpu-core/issues
- Documentation: https://docs.dantegpu.com
- Discord: https://discord.gg/dantegpu