Skip to content

Commit

Permalink
Add explicit datetime annotations to timestamp cols
Browse files Browse the repository at this point in the history
  • Loading branch information
airforce270 committed Aug 17, 2024
1 parent ca82fdf commit b496348
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
40 changes: 32 additions & 8 deletions database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ var AllModels = []any{

// BotBan represents a bot being banned from a channel.
type BotBan struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// Platform contains the which platform this channel is on.
Platform string
Expand All @@ -33,7 +36,10 @@ type BotBan struct {

// ChannelCommandCooldown contains a record of a command cooldown in a channel.
type ChannelCommandCooldown struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// Channel is the channel the command has a cooldown in.
Channel string
Expand All @@ -45,7 +51,10 @@ type ChannelCommandCooldown struct {

// Duel represents a gamba duel.
type Duel struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// UserID is the ID of the user that initiated the duel.
UserID uint
Expand All @@ -67,7 +76,10 @@ type Duel struct {

// GambaTransaction represents a single gamba transaction.
type GambaTransaction struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// UserID is the ID of the user that executed the transaction.
UserID uint
Expand All @@ -81,7 +93,10 @@ type GambaTransaction struct {

// JoinedChannel represents a channel the bot should join.
type JoinedChannel struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// Platform contains the which platform this channel is on.
Platform string
Expand All @@ -97,7 +112,10 @@ type JoinedChannel struct {

// Message represents a chat message.
type Message struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// Text contains the text of the message.
Text string
Expand All @@ -114,7 +132,10 @@ type Message struct {

// User represents a user.
type User struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// TwitchID is the user's ID on Twitch, if known
TwitchID string
Expand All @@ -124,7 +145,10 @@ type User struct {

// UserCommandCooldown contains a record of a command cooldown for a user.
type UserCommandCooldown struct {
gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time `gorm:"type:datetime"`
UpdatedAt time.Time `gorm:"type:datetime"`
DeletedAt gorm.DeletedAt `gorm:"index"`

// UserID is the ID of the user with the cooldown.
UserID uint
Expand Down
48 changes: 12 additions & 36 deletions gamba/gamba_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,35 +286,27 @@ func TestDeduplicateByUser(t *testing.T) {
input: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: true,
},
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: true,
},
},
want: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: true,
},
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: true,
},
Expand All @@ -325,35 +317,27 @@ func TestDeduplicateByUser(t *testing.T) {
input: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: false,
},
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: false,
},
},
want: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: false,
},
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: false,
},
Expand All @@ -364,35 +348,27 @@ func TestDeduplicateByUser(t *testing.T) {
input: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: false,
},
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: true,
},
},
want: []grant{
{
User: models.User{
Model: gorm.Model{
ID: 2,
},
ID: 2,
},
IsActive: true,
},
{
User: models.User{
Model: gorm.Model{
ID: 1,
},
ID: 1,
},
IsActive: false,
},
Expand Down

0 comments on commit b496348

Please sign in to comment.