diff --git a/models/commit_status.go b/models/commit_status.go index 5d637afc2b580..bdde476a4def1 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -21,12 +21,11 @@ import ( // CommitStatus holds a single Status of a single Commit type CommitStatus struct { - ID int64 `xorm:"pk autoincr"` - Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + ID int64 `xorm:"pk autoincr INDEX UNIQUE(repo_sha_id)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_id)"` Repo *Repository `xorm:"-"` State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_id)"` TargetURL string `xorm:"TEXT"` Description string `xorm:"TEXT"` ContextHash string `xorm:"char(40) index"` @@ -130,9 +129,9 @@ func sortCommitStatusesSession(sess *xorm.Session, sortType string) { case "leastupdate": sess.Asc("updated_unix") case "leastindex": - sess.Desc("index") + sess.Desc("id") case "highestindex": - sess.Asc("index") + sess.Asc("id") default: sess.Desc("created_unix") } @@ -217,30 +216,12 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { opts.CommitStatus.CreatorID = opts.Creator.ID opts.CommitStatus.RepoID = opts.Repo.ID - // Get the next Status Index - var nextIndex int64 - lastCommitStatus := &CommitStatus{ - SHA: opts.SHA, - RepoID: opts.Repo.ID, - } - has, err := sess.Desc("index").Limit(1).Get(lastCommitStatus) - if err != nil { - if err := sess.Rollback(); err != nil { - log.Error("NewCommitStatus: sess.Rollback: %v", err) - } - return fmt.Errorf("NewCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err) - } - if has { - log.Debug("NewCommitStatus[%s, %s]: found", repoPath, opts.SHA) - nextIndex = lastCommitStatus.Index - } - opts.CommitStatus.Index = nextIndex + 1 - log.Debug("NewCommitStatus[%s, %s]: %d", repoPath, opts.SHA, opts.CommitStatus.Index) + log.Debug("NewCommitStatus[%s, %s]", repoPath, opts.SHA) opts.CommitStatus.ContextHash = hashCommitStatusContext(opts.CommitStatus.Context) // Insert new CommitStatus - if _, err = sess.Insert(opts.CommitStatus); err != nil { + if _, err := sess.Insert(opts.CommitStatus); err != nil { if err := sess.Rollback(); err != nil { log.Error("Insert CommitStatus: sess.Rollback: %v", err) } diff --git a/models/fixtures/commit_status.yml b/models/fixtures/commit_status.yml index 20d57975ef40d..6161b7c7bd105 100644 --- a/models/fixtures/commit_status.yml +++ b/models/fixtures/commit_status.yml @@ -1,6 +1,5 @@ - id: 1 - index: 1 repo_id: 1 state: "pending" sha: "1234123412341234123412341234123412341234" @@ -11,7 +10,6 @@ - id: 2 - index: 2 repo_id: 1 state: "warning" sha: "1234123412341234123412341234123412341234" @@ -22,7 +20,6 @@ - id: 3 - index: 3 repo_id: 1 state: "success" sha: "1234123412341234123412341234123412341234" @@ -33,7 +30,6 @@ - id: 4 - index: 4 repo_id: 1 state: "failure" sha: "1234123412341234123412341234123412341234" @@ -44,7 +40,6 @@ - id: 5 - index: 5 repo_id: 1 state: "error" sha: "1234123412341234123412341234123412341234" diff --git a/modules/convert/status.go b/modules/convert/status.go index f972fc333c133..1f0fe457694ec 100644 --- a/modules/convert/status.go +++ b/modules/convert/status.go @@ -17,7 +17,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { State: status.State, TargetURL: status.TargetURL, Description: status.Description, - ID: status.Index, + ID: status.ID, URL: status.APIURL(), Context: status.Context, }