diff --git a/db/models/sc_price_history.go b/db/models/sc_price_history.go index 8fae07e..6b75f6c 100644 --- a/db/models/sc_price_history.go +++ b/db/models/sc_price_history.go @@ -4,8 +4,11 @@ import ( "time" "gorm.io/gorm" + "gorm.io/gorm/schema" ) +var _ schema.Tabler = (*SCPriceHistory)(nil) + func init() { registerModel(&SCPriceHistory{}) } @@ -15,3 +18,7 @@ type SCPriceHistory struct { CreatedAt time.Time `gorm:"index:idx_rate"` Rate float64 `gorm:"index:idx_rate"` } + +func (SCPriceHistory) TableName() string { + return "sc_price_history" +} diff --git a/renter/price_tracker.go b/renter/price_tracker.go index 1dd6327..3dc9fcf 100644 --- a/renter/price_tracker.go +++ b/renter/price_tracker.go @@ -79,7 +79,7 @@ func (p PriceTracker) updatePrices() error { SELECT AVG(rate) as average_rate FROM ( SELECT rate FROM ( SELECT rate, ROW_NUMBER() OVER (PARTITION BY DATE(created_at) ORDER BY created_at DESC) as rn - FROM sc_price_histories + FROM sc_price_history WHERE created_at >= NOW() - INTERVAL ? day ) tmp WHERE rn = 1 ) final;