From beffe71ea60224e88f957505d35d31f2188d9a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Fri, 30 Sep 2022 17:14:05 +0200 Subject: [PATCH] feat: add leaderboard data model --- config/config.go | 3 +++ models/leaderboard.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 models/leaderboard.go diff --git a/config/config.go b/config/config.go index cff5a47..be82c86 100644 --- a/config/config.go +++ b/config/config.go @@ -216,6 +216,9 @@ func (c *Config) GetMigrationFunc(dbDialect string) models.MigrationFunc { if err := db.AutoMigrate(&models.Diagnostics{}); err != nil && !c.Db.AutoMigrateFailSilently { return err } + if err := db.AutoMigrate(&models.LeaderboardItem{}); err != nil && !c.Db.AutoMigrateFailSilently { + return err + } return nil } } diff --git a/models/leaderboard.go b/models/leaderboard.go new file mode 100644 index 0000000..32949f2 --- /dev/null +++ b/models/leaderboard.go @@ -0,0 +1,15 @@ +package models + +import "time" + +type LeaderboardItem struct { + ID uint `json:"-" gorm:"primary_key; size:32"` + User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` + UserID string `json:"user_id" gorm:"not null; index:idx_leaderboard_user"` + Rank uint `json:"rank" gorm:"not null; size:16"` + Interval string `json:"interval" gorm:"not null; size:32; index:idx_leaderboard_combined"` + By uint8 `json:"aggregated_by" gorm:"index:idx_leaderboard_combined"` + Total time.Duration `json:"total" gorm:"not null" swaggertype:"primitive,integer"` + Key string `json:"key" gorm:"size:255"` + CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` +}