@@ -23,10 +23,27 @@ type Campaign struct {
2323 CreatorName string `json:"creator_name"`
2424 PercentFunded float64 `json:"percent_funded"`
2525 Slug string `json:"slug"`
26+ Velocity24h float64 `gorm:"default:0" json:"velocity_24h"`
27+ PleDelta24h float64 `gorm:"default:0" json:"pledge_delta_24h"`
2628 FirstSeenAt time.Time `gorm:"not null;default:now()" json:"first_seen_at"`
2729 LastUpdatedAt time.Time `gorm:"not null;default:now()" json:"last_updated_at"`
2830}
2931
32+ type CampaignSnapshot struct {
33+ ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
34+ CampaignPID string `gorm:"index;not null" json:"campaign_pid"`
35+ PledgedAmount float64 `json:"pledged_amount"`
36+ PercentFunded float64 `json:"percent_funded"`
37+ SnapshotAt time.Time `gorm:"index;not null;default:now()" json:"snapshot_at"`
38+ }
39+
40+ func (s * CampaignSnapshot ) BeforeCreate (tx * gorm.DB ) error {
41+ if s .ID == uuid .Nil {
42+ s .ID = uuid .New ()
43+ }
44+ return nil
45+ }
46+
3047type Category struct {
3148 ID string `gorm:"primaryKey" json:"id"`
3249 Name string `gorm:"not null" json:"name"`
@@ -47,20 +64,25 @@ func (d *Device) BeforeCreate(tx *gorm.DB) error {
4764}
4865
4966type Alert struct {
50- ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
51- DeviceID uuid.UUID `gorm:"type:uuid;index;not null" json:"device_id"`
52- Keyword string `gorm:"not null" json:"keyword"`
53- CategoryID string `json:"category_id,omitempty"`
54- MinPercent float64 `gorm:"default:0" json:"min_percent"`
55- IsEnabled bool `gorm:"default:true" json:"is_enabled"`
56- CreatedAt time.Time `json:"created_at"`
57- LastMatchedAt * time.Time `json:"last_matched_at,omitempty"`
67+ ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
68+ DeviceID uuid.UUID `gorm:"type:uuid;index;not null" json:"device_id"`
69+ AlertType string `gorm:"not null;default:'keyword'" json:"alert_type"`
70+ Keyword string `json:"keyword"`
71+ CategoryID string `json:"category_id,omitempty"`
72+ MinPercent float64 `gorm:"default:0" json:"min_percent"`
73+ VelocityThresh float64 `gorm:"default:0" json:"velocity_thresh"`
74+ IsEnabled bool `gorm:"default:true" json:"is_enabled"`
75+ CreatedAt time.Time `json:"created_at"`
76+ LastMatchedAt * time.Time `json:"last_matched_at,omitempty"`
5877}
5978
6079func (a * Alert ) BeforeCreate (tx * gorm.DB ) error {
6180 if a .ID == uuid .Nil {
6281 a .ID = uuid .New ()
6382 }
83+ if a .AlertType == "" {
84+ a .AlertType = "keyword"
85+ }
6486 return nil
6587}
6688
0 commit comments