mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Merge branch 'master' into feat/approval-new
# Conflicts: # models/issue_comment.go # models/migrations/migrations.go # models/migrations/v64.go # models/models.go # public/css/index.css
This commit is contained in:
@@ -181,6 +181,8 @@ var migrations = []Migration{
|
||||
// v63 -> v64
|
||||
NewMigration("add language column for user setting", addLanguageSetting),
|
||||
// v64 -> v65
|
||||
NewMigration("add multiple assignees", addMultipleAssignees),
|
||||
// v65 -> v66
|
||||
NewMigration("add review", addReview),
|
||||
}
|
||||
|
||||
@@ -231,7 +233,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
|
||||
return nil
|
||||
}
|
||||
|
||||
func dropTableColumns(x *xorm.Engine, tableName string, columnNames ...string) (err error) {
|
||||
func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...string) (err error) {
|
||||
if tableName == "" || len(columnNames) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -247,17 +249,10 @@ func dropTableColumns(x *xorm.Engine, tableName string, columnNames ...string) (
|
||||
}
|
||||
cols += "DROP COLUMN `" + col + "`"
|
||||
}
|
||||
if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
|
||||
}
|
||||
case setting.UseMSSQL:
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cols := ""
|
||||
for _, col := range columnNames {
|
||||
if cols != "" {
|
||||
|
@@ -9,5 +9,15 @@ import (
|
||||
)
|
||||
|
||||
func removeIsOwnerColumnFromOrgUser(x *xorm.Engine) (err error) {
|
||||
return dropTableColumns(x, "org_user", "is_owner", "num_teams")
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := dropTableColumns(sess, "org_user", "is_owner", "num_teams"); err != nil {
|
||||
return err
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
@@ -5,27 +5,127 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func addReview(x *xorm.Engine) error {
|
||||
// Review see models/review.go
|
||||
type Review struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type string
|
||||
ReviewerID int64 `xorm:"index"`
|
||||
IssueID int64 `xorm:"index"`
|
||||
Content string
|
||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||
func addMultipleAssignees(x *xorm.Engine) error {
|
||||
|
||||
// Redeclare issue struct
|
||||
type Issue struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
|
||||
Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
|
||||
PosterID int64 `xorm:"INDEX"`
|
||||
Title string `xorm:"name"`
|
||||
Content string `xorm:"TEXT"`
|
||||
MilestoneID int64 `xorm:"INDEX"`
|
||||
Priority int
|
||||
AssigneeID int64 `xorm:"INDEX"`
|
||||
IsClosed bool `xorm:"INDEX"`
|
||||
IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
|
||||
NumComments int
|
||||
Ref string
|
||||
|
||||
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
|
||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||
ClosedUnix util.TimeStamp `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
if err := x.Sync2(new(Review)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
// Updated the comment table
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type int
|
||||
PosterID int64 `xorm:"INDEX"`
|
||||
IssueID int64 `xorm:"INDEX"`
|
||||
LabelID int64
|
||||
OldMilestoneID int64
|
||||
MilestoneID int64
|
||||
OldAssigneeID int64
|
||||
AssigneeID int64
|
||||
RemovedAssignee bool
|
||||
OldTitle string
|
||||
NewTitle string
|
||||
|
||||
CommitID int64
|
||||
Line int64
|
||||
Content string `xorm:"TEXT"`
|
||||
RenderedContent string `xorm:"-"`
|
||||
|
||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||
|
||||
// Reference issue in commit message
|
||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||
}
|
||||
return nil
|
||||
|
||||
// Create the table
|
||||
type IssueAssignees struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
AssigneeID int64 `xorm:"INDEX"`
|
||||
IssueID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
if err := x.Sync2(IssueAssignees{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := x.Sync2(Comment{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Range over all issues and insert a new entry for each issue/assignee
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allIssues := []Issue{}
|
||||
if err := sess.Find(&allIssues); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, issue := range allIssues {
|
||||
if issue.AssigneeID != 0 {
|
||||
_, err := sess.Insert(IssueAssignees{IssueID: issue.ID, AssigneeID: issue.AssigneeID})
|
||||
if err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate comments
|
||||
// First update everything to not have nulls in db
|
||||
if _, err := sess.Where("type = ?", 9).Cols("removed_assignee").Update(Comment{RemovedAssignee: false}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allAssignementComments := []Comment{}
|
||||
if err := sess.Where("type = ?", 9).Find(&allAssignementComments); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, comment := range allAssignementComments {
|
||||
// Everytime where OldAssigneeID is > 0, the assignement was removed.
|
||||
if comment.OldAssigneeID > 0 {
|
||||
_, err := sess.ID(comment.ID).Update(Comment{RemovedAssignee: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := dropTableColumns(sess, "issue", "assignee_id"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := dropTableColumns(sess, "issue_user", "is_assigned"); err != nil {
|
||||
return err
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
Reference in New Issue
Block a user