mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 23:07:01 +08:00
feat: migrate store layer to GORM with PostgreSQL support
- Migrate all store packages from raw database/sql to GORM ORM - Add PostgreSQL support alongside SQLite - Move EncryptedString type to crypto package for cleaner architecture - Add automatic encryption/decryption for sensitive fields (API keys, secrets) - Fix PostgreSQL AutoMigrate conflicts by skipping existing tables - Fix duplicate /klines route registration - Update tests to use GORM database connections - Add database configuration support in config package
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package trader
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"math"
|
||||
"nofx/store"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
// TestHyperliquidOrderDirectionParsing tests Dir field parsing
|
||||
@@ -75,11 +76,12 @@ func TestHyperliquidOrderDirectionParsing(t *testing.T) {
|
||||
// TestHyperliquidPositionBuilding tests the complete flow of position building
|
||||
func TestHyperliquidPositionBuilding(t *testing.T) {
|
||||
// Setup in-memory database
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test database: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// Initialize stores
|
||||
positionStore := store.NewPositionStore(db)
|
||||
@@ -304,11 +306,12 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
|
||||
// TestHyperliquidBugScenario tests the exact bug we fixed
|
||||
func TestHyperliquidBugScenario(t *testing.T) {
|
||||
// Setup database
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test database: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
positionStore := store.NewPositionStore(db)
|
||||
if err := positionStore.InitTables(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user