refactor: change SCPriceHistory table name
This commit is contained in:
parent
e425c038e1
commit
5687e72a32
|
@ -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"
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue