feat: migrate from SQLite to PostgreSQL + Redis architecture

Major database migration to modernize the AI trading system:

• **Database Migration**:
  - Add PostgreSQL 15 and Redis 7 services to docker-compose
  - Create comprehensive PostgreSQL schema with proper indexes and triggers
  - Implement DatabaseInterface for multi-database support
  - Add automatic environment-based database selection

• **Infrastructure**:
  - PostgreSQL: ACID transactions, better concurrency, JSON support
  - Redis: High-performance caching layer (prepared for future use)
  - Docker services with health checks and dependency management
  - Persistent volumes for data safety

• **Code Refactoring**:
  - Abstract database operations through DatabaseInterface
  - Implement PostgreSQL-specific operations with proper syntax
  - Update all SQL queries to support both SQLite and PostgreSQL
  - Fix foreign key constraints and data type conversions

• **Migration Tools**:
  - Automated data migration script from SQLite to PostgreSQL
  - Complete backup and restore procedures
  - One-click migration script with validation

• **Compatibility**:
  - Backward compatible with existing SQLite deployments
  - Environment variable driven database selection
  - Preserved all existing functionality and data

🎯 Benefits: Better performance, scalability, and reliability for production deployments
This commit is contained in:
icy
2025-11-04 15:09:11 +08:00
parent 14a0ef090e
commit 22c2cfdede
14 changed files with 1437 additions and 12 deletions

View File

@@ -39,7 +39,7 @@ func NewTraderManager() *TraderManager {
}
// LoadTradersFromDatabase 从数据库加载所有交易员到内存
func (tm *TraderManager) LoadTradersFromDatabase(database *config.Database) error {
func (tm *TraderManager) LoadTradersFromDatabase(database config.DatabaseInterface) error {
tm.mu.Lock()
defer tm.mu.Unlock()
@@ -709,7 +709,7 @@ func containsUserPrefix(traderID string) bool {
}
// LoadUserTraders 为特定用户加载交易员到内存
func (tm *TraderManager) LoadUserTraders(database *config.Database, userID string) error {
func (tm *TraderManager) LoadUserTraders(database config.DatabaseInterface, userID string) error {
tm.mu.Lock()
defer tm.mu.Unlock()