aboutsummaryrefslogtreecommitdiff
path: root/internal/db/access_tokens.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/access_tokens.go')
-rw-r--r--internal/db/access_tokens.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/internal/db/access_tokens.go b/internal/db/access_tokens.go
index 5345a65f..7ed44ae9 100644
--- a/internal/db/access_tokens.go
+++ b/internal/db/access_tokens.go
@@ -42,7 +42,7 @@ var AccessTokens AccessTokensStore
// AccessToken is a personal access token.
type AccessToken struct {
- ID int64
+ ID int64 `gorm:"primarykey"`
UserID int64 `xorm:"uid" gorm:"column:uid;index"`
Name string
Sha1 string `gorm:"type:VARCHAR(40);unique"`
@@ -67,9 +67,11 @@ func (t *AccessToken) BeforeCreate(tx *gorm.DB) error {
// AfterFind implements the GORM query hook.
func (t *AccessToken) AfterFind(tx *gorm.DB) error {
t.Created = time.Unix(t.CreatedUnix, 0).Local()
- t.Updated = time.Unix(t.UpdatedUnix, 0).Local()
- t.HasUsed = t.Updated.After(t.Created)
- t.HasRecentActivity = t.Updated.Add(7 * 24 * time.Hour).After(tx.NowFunc())
+ if t.UpdatedUnix > 0 {
+ t.Updated = time.Unix(t.UpdatedUnix, 0).Local()
+ t.HasUsed = t.Updated.After(t.Created)
+ t.HasRecentActivity = t.Updated.Add(7 * 24 * time.Hour).After(tx.NowFunc())
+ }
return nil
}