diff options
Diffstat (limited to 'internal/db/repos.go')
-rw-r--r-- | internal/db/repos.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/internal/db/repos.go b/internal/db/repos.go index 08cc6485..fc5bce03 100644 --- a/internal/db/repos.go +++ b/internal/db/repos.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/jinzhu/gorm" + "gorm.io/gorm" "gogs.io/gogs/internal/errutil" ) @@ -26,19 +26,24 @@ type ReposStore interface { var Repos ReposStore // NOTE: This is a GORM create hook. -func (r *Repository) BeforeCreate() { - r.CreatedUnix = gorm.NowFunc().Unix() +func (r *Repository) BeforeCreate(tx *gorm.DB) error { + if r.CreatedUnix == 0 { + r.CreatedUnix = tx.NowFunc().Unix() + } + return nil } // NOTE: This is a GORM update hook. -func (r *Repository) BeforeUpdate() { - r.UpdatedUnix = gorm.NowFunc().Unix() +func (r *Repository) BeforeUpdate(tx *gorm.DB) error { + r.UpdatedUnix = tx.NowFunc().Unix() + return nil } // NOTE: This is a GORM query hook. -func (r *Repository) AfterFind() { +func (r *Repository) AfterFind(tx *gorm.DB) error { r.Created = time.Unix(r.CreatedUnix, 0).Local() r.Updated = time.Unix(r.UpdatedUnix, 0).Local() + return nil } var _ ReposStore = (*repos)(nil) @@ -129,7 +134,7 @@ func (db *repos) GetByName(ownerID int64, name string) (*Repository, error) { repo := new(Repository) err := db.Where("owner_id = ? AND lower_name = ?", ownerID, strings.ToLower(name)).First(repo).Error if err != nil { - if gorm.IsRecordNotFoundError(err) { + if err == gorm.ErrRecordNotFound { return nil, ErrRepoNotExist{args: map[string]interface{}{"ownerID": ownerID, "name": name}} } return nil, err |