diff --git a/models/issue_reaction.go b/models/issue_reaction.go index ad85e5747c3db..ae22f4443e429 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -18,12 +18,12 @@ import ( // Reaction represents a reactions on issues and comments. type Reaction struct { ID int64 `xorm:"pk autoincr"` - Type string `xorm:"INDEX UNIQUE(s) NOT NULL"` + Type string `xorm:"VARCHAR(32) INDEX UNIQUE(s) NOT NULL"` IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` CommentID int64 `xorm:"INDEX UNIQUE(s)"` UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` OriginalAuthorID int64 `xorm:"INDEX UNIQUE(s) NOT NULL DEFAULT(0)"` - OriginalAuthor string `xorm:"INDEX UNIQUE(s)"` + OriginalAuthor string `xorm:"VARCHAR(64) INDEX UNIQUE(s)"` User *User `xorm:"-"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` } diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 3227f6f75451b..e0e7e6ef4c17a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -281,6 +281,8 @@ var migrations = []Migration{ NewMigration("Where Password is Valid with Empty String delete it", recalculateUserEmptyPWD), // v167 -> v168 NewMigration("Add user redirect", addUserRedirect), + // v168 -> v169 + NewMigration("Restrict user and reaction table index column size", restrictUserAndReactionColumnSize), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v159.go b/models/migrations/v159.go index 68043b9412774..53dd4c5bfd9dc 100644 --- a/models/migrations/v159.go +++ b/models/migrations/v159.go @@ -14,12 +14,12 @@ func updateReactionConstraint(x *xorm.Engine) error { // Reaction represents a reactions on issues and comments. type Reaction struct { ID int64 `xorm:"pk autoincr"` - Type string `xorm:"INDEX UNIQUE(s) NOT NULL"` + Type string `xorm:"VARCHAR(32) INDEX UNIQUE(s) NOT NULL"` IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` CommentID int64 `xorm:"INDEX UNIQUE(s)"` UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` OriginalAuthorID int64 `xorm:"INDEX UNIQUE(s) NOT NULL DEFAULT(0)"` - OriginalAuthor string `xorm:"INDEX UNIQUE(s)"` + OriginalAuthor string `xorm:"VARCHAR(64) INDEX UNIQUE(s)"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` } diff --git a/models/migrations/v168.go b/models/migrations/v168.go new file mode 100644 index 0000000000000..c8ea910e3135b --- /dev/null +++ b/models/migrations/v168.go @@ -0,0 +1,27 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "xorm.io/xorm" +) + +func restrictUserAndReactionColumnSize(x *xorm.Engine) error { + type Reaction struct { + ID int64 `xorm:"pk autoincr"` + Type string `xorm:"VARCHAR(32) INDEX NOT NULL"` + OriginalAuthor string `xorm:"VARCHAR(64) INDEX"` + } + if err := x.Sync2(new(Reaction)); err != nil { + return err + } + + type User struct { + ID int64 `xorm:"pk autoincr"` + LowerName string `xorm:"VARCHAR(64) UNIQUE NOT NULL"` + Name string `xorm:"VARCHAR(64) UNIQUE NOT NULL"` + } + return x.Sync2(new(User)) +} diff --git a/models/user.go b/models/user.go index 8147c9f62610b..06c652bc8b701 100644 --- a/models/user.go +++ b/models/user.go @@ -91,8 +91,8 @@ var ( // User represents the object of individual and member of organization. type User struct { ID int64 `xorm:"pk autoincr"` - LowerName string `xorm:"UNIQUE NOT NULL"` - Name string `xorm:"UNIQUE NOT NULL"` + LowerName string `xorm:"VARCHAR(64) UNIQUE NOT NULL"` + Name string `xorm:"VARCHAR(64) UNIQUE NOT NULL"` FullName string // Email is the primary email address (to be used for communication) Email string `xorm:"NOT NULL"`