refactor: change SCPriceHistory table name

This commit is contained in:
Derrick Hammer 2024-03-10 13:58:45 -04:00
parent e425c038e1
commit 5687e72a32
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 8 additions and 1 deletions

View File

@ -4,8 +4,11 @@ import (
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/schema"
) )
var _ schema.Tabler = (*SCPriceHistory)(nil)
func init() { func init() {
registerModel(&SCPriceHistory{}) registerModel(&SCPriceHistory{})
} }
@ -15,3 +18,7 @@ type SCPriceHistory struct {
CreatedAt time.Time `gorm:"index:idx_rate"` CreatedAt time.Time `gorm:"index:idx_rate"`
Rate float64 `gorm:"index:idx_rate"` Rate float64 `gorm:"index:idx_rate"`
} }
func (SCPriceHistory) TableName() string {
return "sc_price_history"
}

View File

@ -79,7 +79,7 @@ func (p PriceTracker) updatePrices() error {
SELECT AVG(rate) as average_rate FROM ( SELECT AVG(rate) as average_rate FROM (
SELECT rate FROM ( SELECT rate FROM (
SELECT rate, ROW_NUMBER() OVER (PARTITION BY DATE(created_at) ORDER BY created_at DESC) as rn 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 WHERE created_at >= NOW() - INTERVAL ? day
) tmp WHERE rn = 1 ) tmp WHERE rn = 1
) final; ) final;