diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 8 | ||||
-rw-r--r-- | models/admin.go | 7 | ||||
-rw-r--r-- | models/attachment.go | 7 | ||||
-rw-r--r-- | models/branches.go | 15 | ||||
-rw-r--r-- | models/issue.go | 12 | ||||
-rw-r--r-- | models/issue_comment.go | 16 | ||||
-rw-r--r-- | models/lfs.go | 10 | ||||
-rw-r--r-- | models/login_source.go | 15 | ||||
-rw-r--r-- | models/models.go | 1 | ||||
-rw-r--r-- | models/repo.go | 15 | ||||
-rw-r--r-- | models/repo_mirror.go | 16 | ||||
-rw-r--r-- | models/ssh_key.go | 36 | ||||
-rw-r--r-- | models/status.go | 15 | ||||
-rw-r--r-- | models/token.go | 14 | ||||
-rw-r--r-- | models/twofactor.go | 14 | ||||
-rw-r--r-- | models/unit_tests.go | 1 | ||||
-rw-r--r-- | models/user.go | 12 | ||||
-rw-r--r-- | models/webhook.go | 17 |
18 files changed, 48 insertions, 183 deletions
diff --git a/models/action.go b/models/action.go index 32b3dbd7bc..8793a4a24d 100644 --- a/models/action.go +++ b/models/action.go @@ -86,13 +86,7 @@ type Action struct { IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` Content string `xorm:"TEXT"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert will be invoked by XORM before inserting a record -// representing this object. -func (a *Action) BeforeInsert() { - a.CreatedUnix = time.Now().Unix() + CreatedUnix int64 `xorm:"INDEX created"` } // AfterSet updates the webhook object upon setting a column. diff --git a/models/admin.go b/models/admin.go index f8645202d8..eb78f6e865 100644 --- a/models/admin.go +++ b/models/admin.go @@ -29,12 +29,7 @@ type Notice struct { Type NoticeType Description string `xorm:"TEXT"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (n *Notice) BeforeInsert() { - n.CreatedUnix = time.Now().Unix() + CreatedUnix int64 `xorm:"INDEX created"` } // AfterSet is invoked from XORM after setting the value of a field of this object. diff --git a/models/attachment.go b/models/attachment.go index 3b3521bf60..2731ca4b7a 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -28,12 +28,7 @@ type Attachment struct { Name string DownloadCount int64 `xorm:"DEFAULT 0"` Created time.Time `xorm:"-"` - CreatedUnix int64 -} - -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (a *Attachment) BeforeInsert() { - a.CreatedUnix = time.Now().Unix() + CreatedUnix int64 `xorm:"created"` } // AfterSet is invoked from XORM after setting the value of a field of diff --git a/models/branches.go b/models/branches.go index 6115f9c687..4461da0067 100644 --- a/models/branches.go +++ b/models/branches.go @@ -22,20 +22,9 @@ type ProtectedBranch struct { BranchName string `xorm:"UNIQUE(s)"` CanPush bool Created time.Time `xorm:"-"` - CreatedUnix int64 + CreatedUnix int64 `xorm:"created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 -} - -// BeforeInsert before protected branch insert create and update time -func (protectBranch *ProtectedBranch) BeforeInsert() { - protectBranch.CreatedUnix = time.Now().Unix() - protectBranch.UpdatedUnix = protectBranch.CreatedUnix -} - -// BeforeUpdate before protected branch update time -func (protectBranch *ProtectedBranch) BeforeUpdate() { - protectBranch.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"updated"` } // GetProtectedBranchByRepoID getting protected branch by repo ID diff --git a/models/issue.go b/models/issue.go index 8723dda913..2b71e0776d 100644 --- a/models/issue.go +++ b/models/issue.go @@ -54,23 +54,16 @@ type Issue struct { Deadline time.Time `xorm:"-"` DeadlineUnix int64 `xorm:"INDEX"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` + UpdatedUnix int64 `xorm:"INDEX updated"` Attachments []*Attachment `xorm:"-"` Comments []*Comment `xorm:"-"` } -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (issue *Issue) BeforeInsert() { - issue.CreatedUnix = time.Now().Unix() - issue.UpdatedUnix = issue.CreatedUnix -} - // BeforeUpdate is invoked from XORM before updating this object. func (issue *Issue) BeforeUpdate() { - issue.UpdatedUnix = time.Now().Unix() issue.DeadlineUnix = issue.Deadline.Unix() } @@ -581,7 +574,6 @@ func (issue *Issue) ReadBy(userID int64) error { } func updateIssueCols(e Engine, issue *Issue, cols ...string) error { - cols = append(cols, "updated_unix") if _, err := e.Id(issue.ID).Cols(cols...).Update(issue); err != nil { return err } diff --git a/models/issue_comment.go b/models/issue_comment.go index fe2223e9d2..6c9c75b1e4 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -99,9 +99,9 @@ type Comment struct { RenderedContent string `xorm:"-"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` + UpdatedUnix int64 `xorm:"INDEX updated"` // Reference issue in commit message CommitSHA string `xorm:"VARCHAR(40)"` @@ -112,18 +112,6 @@ type Comment struct { ShowTag CommentTag `xorm:"-"` } -// BeforeInsert will be invoked by XORM before inserting a record -// representing this object. -func (c *Comment) BeforeInsert() { - c.CreatedUnix = time.Now().Unix() - c.UpdatedUnix = c.CreatedUnix -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (c *Comment) BeforeUpdate() { - c.UpdatedUnix = time.Now().Unix() -} - // AfterSet is invoked from XORM after setting the value of a field of this object. func (c *Comment) AfterSet(colName string, _ xorm.Cell) { var err error diff --git a/models/lfs.go b/models/lfs.go index f908cae1f2..be99306d75 100644 --- a/models/lfs.go +++ b/models/lfs.go @@ -2,8 +2,9 @@ package models import ( "errors" - "github.com/go-xorm/xorm" "time" + + "github.com/go-xorm/xorm" ) // LFSMetaObject stores metadata for LFS tracked files. @@ -14,7 +15,7 @@ type LFSMetaObject struct { RepositoryID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"` Existing bool `xorm:"-"` Created time.Time `xorm:"-"` - CreatedUnix int64 + CreatedUnix int64 `xorm:"created"` } // LFSTokenResponse defines the JSON structure in which the JWT token is stored. @@ -108,11 +109,6 @@ func RemoveLFSMetaObjectByOid(oid string) error { return sess.Commit() } -// BeforeInsert sets the time at which the LFSMetaObject was created. -func (m *LFSMetaObject) BeforeInsert() { - m.CreatedUnix = time.Now().Unix() -} - // AfterSet stores the LFSMetaObject creation time in the database as local time. func (m *LFSMetaObject) AfterSet(colName string, _ xorm.Cell) { switch colName { diff --git a/models/login_source.go b/models/login_source.go index e4dc77714c..186a5e0514 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -148,20 +148,9 @@ type LoginSource struct { Cfg core.Conversion `xorm:"TEXT"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (source *LoginSource) BeforeInsert() { - source.CreatedUnix = time.Now().Unix() - source.UpdatedUnix = source.CreatedUnix -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (source *LoginSource) BeforeUpdate() { - source.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"INDEX updated"` } // Cell2Int64 converts a xorm.Cell type to int64, diff --git a/models/models.go b/models/models.go index 0bcb3674da..1e64f70f4f 100644 --- a/models/models.go +++ b/models/models.go @@ -241,6 +241,7 @@ func NewTestEngine(x *xorm.Engine) (err error) { x.SetMapper(core.GonicMapper{}) x.SetLogger(log.XORMLogger) + x.ShowSQL(!setting.ProdMode) return x.StoreEngine("InnoDB").Sync2(tables...) } diff --git a/models/repo.go b/models/repo.go index 1cce3854ee..a2e63e2af7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -211,20 +211,9 @@ type Repository struct { Size int64 `xorm:"NOT NULL DEFAULT 0"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (repo *Repository) BeforeInsert() { - repo.CreatedUnix = time.Now().Unix() - repo.UpdatedUnix = repo.CreatedUnix -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (repo *Repository) BeforeUpdate() { - repo.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"INDEX updated"` } // AfterSet is invoked from XORM after setting the value of a field of this object. diff --git a/models/repo_mirror.go b/models/repo_mirror.go index 4588597743..526b7cd02e 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -40,18 +40,26 @@ type Mirror struct { // BeforeInsert will be invoked by XORM before inserting a record func (m *Mirror) BeforeInsert() { - m.UpdatedUnix = time.Now().Unix() - m.NextUpdateUnix = m.NextUpdate.Unix() + if m != nil { + m.UpdatedUnix = time.Now().Unix() + m.NextUpdateUnix = m.NextUpdate.Unix() + } } // BeforeUpdate is invoked from XORM before updating this object. func (m *Mirror) BeforeUpdate() { - m.UpdatedUnix = time.Now().Unix() - m.NextUpdateUnix = m.NextUpdate.Unix() + if m != nil { + m.UpdatedUnix = time.Now().Unix() + m.NextUpdateUnix = m.NextUpdate.Unix() + } } // AfterSet is invoked from XORM after setting the value of a field of this object. func (m *Mirror) AfterSet(colName string, _ xorm.Cell) { + if m == nil { + return + } + var err error switch colName { case "repo_id": diff --git a/models/ssh_key.go b/models/ssh_key.go index 649c50be6c..873eab3bf3 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -55,21 +55,11 @@ type PublicKey struct { Type KeyType `xorm:"NOT NULL DEFAULT 1"` Created time.Time `xorm:"-"` - CreatedUnix int64 + CreatedUnix int64 `xorm:"created"` Updated time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet. - UpdatedUnix int64 - HasRecentActivity bool `xorm:"-"` - HasUsed bool `xorm:"-"` -} - -// BeforeInsert will be invoked by XORM before inserting a record -func (key *PublicKey) BeforeInsert() { - key.CreatedUnix = time.Now().Unix() -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (key *PublicKey) BeforeUpdate() { - key.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"updated"` + HasRecentActivity bool `xorm:"-"` + HasUsed bool `xorm:"-"` } // AfterSet is invoked from XORM after setting the value of a field of this object. @@ -633,21 +623,11 @@ type DeployKey struct { Content string `xorm:"-"` Created time.Time `xorm:"-"` - CreatedUnix int64 + CreatedUnix int64 `xorm:"created"` Updated time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet. - UpdatedUnix int64 - HasRecentActivity bool `xorm:"-"` - HasUsed bool `xorm:"-"` -} - -// BeforeInsert will be invoked by XORM before inserting a record -func (key *DeployKey) BeforeInsert() { - key.CreatedUnix = time.Now().Unix() -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (key *DeployKey) BeforeUpdate() { - key.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"updated"` + HasRecentActivity bool `xorm:"-"` + HasUsed bool `xorm:"-"` } // AfterSet is invoked from XORM after setting the value of a field of this object. diff --git a/models/status.go b/models/status.go index 2ce588bea5..e300c763ff 100644 --- a/models/status.go +++ b/models/status.go @@ -66,20 +66,9 @@ type CommitStatus struct { CreatorID int64 Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (status *CommitStatus) BeforeInsert() { - status.CreatedUnix = time.Now().Unix() - status.UpdatedUnix = status.CreatedUnix -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (status *CommitStatus) BeforeUpdate() { - status.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"INDEX updated"` } // AfterSet is invoked from XORM after setting the value of a field of diff --git a/models/token.go b/models/token.go index b2e0a28a5a..d4b86eb3ae 100644 --- a/models/token.go +++ b/models/token.go @@ -21,23 +21,13 @@ type AccessToken struct { Sha1 string `xorm:"UNIQUE VARCHAR(40)"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet. - UpdatedUnix int64 `xorm:"INDEX"` + UpdatedUnix int64 `xorm:"INDEX updated"` HasRecentActivity bool `xorm:"-"` HasUsed bool `xorm:"-"` } -// BeforeInsert will be invoked by XORM before inserting a record representing this object. -func (t *AccessToken) BeforeInsert() { - t.CreatedUnix = time.Now().Unix() -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (t *AccessToken) BeforeUpdate() { - t.UpdatedUnix = time.Now().Unix() -} - // AfterSet is invoked from XORM after setting the value of a field of this object. func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) { switch colName { diff --git a/models/twofactor.go b/models/twofactor.go index 4c0d3702db..c983b56a5c 100644 --- a/models/twofactor.go +++ b/models/twofactor.go @@ -26,19 +26,9 @@ type TwoFactor struct { ScratchToken string Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet. - UpdatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert will be invoked by XORM before inserting a record representing this object. -func (t *TwoFactor) BeforeInsert() { - t.CreatedUnix = time.Now().Unix() -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (t *TwoFactor) BeforeUpdate() { - t.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"INDEX updated"` } // AfterSet is invoked from XORM after setting the value of a field of this object. diff --git a/models/unit_tests.go b/models/unit_tests.go index 315627d8e0..ce328b579d 100644 --- a/models/unit_tests.go +++ b/models/unit_tests.go @@ -28,6 +28,7 @@ func CreateTestEngine(fixturesDir string) error { if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil { return err } + x.ShowSQL(true) return InitFixtures(&testfixtures.SQLite{}, fixturesDir) } diff --git a/models/user.go b/models/user.go index 1e2502ebc0..f6d7051013 100644 --- a/models/user.go +++ b/models/user.go @@ -94,9 +94,9 @@ type User struct { Salt string `xorm:"VARCHAR(10)"` Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` + UpdatedUnix int64 `xorm:"INDEX updated"` LastLogin time.Time `xorm:"-"` LastLoginUnix int64 `xorm:"INDEX"` @@ -135,18 +135,11 @@ type User struct { DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` } -// BeforeInsert is invoked from XORM before inserting an object of this type. -func (u *User) BeforeInsert() { - u.CreatedUnix = time.Now().Unix() - u.UpdatedUnix = u.CreatedUnix -} - // BeforeUpdate is invoked from XORM before updating this object. func (u *User) BeforeUpdate() { if u.MaxRepoCreation < -1 { u.MaxRepoCreation = -1 } - u.UpdatedUnix = time.Now().Unix() } // SetLastLogin set time to last login @@ -897,7 +890,6 @@ func UpdateUserCols(u *User, cols ...string) error { u.Website = base.TruncateString(u.Website, 255) u.Description = base.TruncateString(u.Description, 255) - cols = append(cols, "updated_unix") _, err := x.Id(u.ID).Cols(cols...).Update(u) return err } diff --git a/models/webhook.go b/models/webhook.go index fa0c498f33..bc7926c233 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -107,22 +107,9 @@ type Webhook struct { LastStatus HookStatus // Last delivery status Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX"` + CreatedUnix int64 `xorm:"INDEX created"` Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` -} - -// BeforeInsert will be invoked by XORM before inserting a record -// representing this object -func (w *Webhook) BeforeInsert() { - w.CreatedUnix = time.Now().Unix() - w.UpdatedUnix = w.CreatedUnix -} - -// BeforeUpdate will be invoked by XORM before updating a record -// representing this object -func (w *Webhook) BeforeUpdate() { - w.UpdatedUnix = time.Now().Unix() + UpdatedUnix int64 `xorm:"INDEX updated"` } // AfterSet updates the webhook object upon setting a column |