From 5687e72a32c16560cedc82531d8c31cb87df0a86 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 10 Mar 2024 13:58:45 -0400 Subject: [PATCH] refactor: change SCPriceHistory table name --- db/models/sc_price_history.go | 7 +++++++ renter/price_tracker.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) 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;