Skip to content

Commit 69016f7

Browse files
committed
connect to mysql using utf8mb4 and change all indexed cols from varchar(255), which is the default, to varchar(191) in order to deal with utf8mb4/innodb 5.6
1 parent 4ceb92f commit 69016f7

13 files changed

+18
-18
lines changed

models/branches.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
type ProtectedBranch struct {
2626
ID int64 `xorm:"pk autoincr"`
2727
RepoID int64 `xorm:"UNIQUE(s)"`
28-
BranchName string `xorm:"UNIQUE(s)"`
28+
BranchName string `xorm:"VARCHAR(191) UNIQUE(s)"`
2929
CanPush bool `xorm:"NOT NULL DEFAULT false"`
3030
EnableWhitelist bool
3131
WhitelistUserIDs []int64 `xorm:"JSON TEXT"`
@@ -287,8 +287,8 @@ func (repo *Repository) DeleteProtectedBranch(id int64) (err error) {
287287
type DeletedBranch struct {
288288
ID int64 `xorm:"pk autoincr"`
289289
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
290-
Name string `xorm:"UNIQUE(s) NOT NULL"`
291-
Commit string `xorm:"UNIQUE(s) NOT NULL"`
290+
Name string `xorm:"VARCHAR(191) UNIQUE(s) NOT NULL"`
291+
Commit string `xorm:"VARCHAR(191) UNIQUE(s) NOT NULL"`
292292
DeletedByID int64 `xorm:"INDEX"`
293293
DeletedBy *User `xorm:"-"`
294294
DeletedUnix util.TimeStamp `xorm:"INDEX created"`

models/external_login_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "github.com/markbates/goth"
88

99
// ExternalLoginUser makes the connecting between some existing user and additional external login sources
1010
type ExternalLoginUser struct {
11-
ExternalID string `xorm:"pk NOT NULL"`
11+
ExternalID string `xorm:"VARCHAR(191) pk NOT NULL"`
1212
UserID int64 `xorm:"INDEX NOT NULL"`
1313
LoginSourceID int64 `xorm:"pk NOT NULL"`
1414
}

models/issue_reaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// Reaction represents a reactions on issues and comments.
1919
type Reaction struct {
2020
ID int64 `xorm:"pk autoincr"`
21-
Type string `xorm:"INDEX UNIQUE(s) NOT NULL"`
21+
Type string `xorm:"VARCHAR(191) INDEX UNIQUE(s) NOT NULL"`
2222
IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`
2323
CommentID int64 `xorm:"INDEX UNIQUE(s)"`
2424
UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`

models/lfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// LFSMetaObject stores metadata for LFS tracked files.
1010
type LFSMetaObject struct {
1111
ID int64 `xorm:"pk autoincr"`
12-
Oid string `xorm:"UNIQUE(s) INDEX NOT NULL"`
12+
Oid string `xorm:"VARCHAR(191) UNIQUE(s) INDEX NOT NULL"`
1313
Size int64 `xorm:"NOT NULL"`
1414
RepositoryID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
1515
Existing bool `xorm:"-"`

models/login_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (cfg *OAuth2Config) ToDB() ([]byte, error) {
142142
type LoginSource struct {
143143
ID int64 `xorm:"pk autoincr"`
144144
Type LoginType
145-
Name string `xorm:"UNIQUE"`
145+
Name string `xorm:"VARCHAR(191) UNIQUE"`
146146
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
147147
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
148148
Cfg core.Conversion `xorm:"TEXT"`

models/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ func getEngine() (*xorm.Engine, error) {
206206
switch DbCfg.Type {
207207
case "mysql":
208208
if DbCfg.Host[0] == '/' { // looks like a unix socket
209-
connStr = fmt.Sprintf("%s:%s@unix(%s)/%s%scharset=utf8&parseTime=true",
209+
connStr = fmt.Sprintf("%s:%s@unix(%s)/%s%scharset=utf8mb4&parseTime=true",
210210
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
211211
} else {
212-
connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8&parseTime=true",
212+
connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8mb4&parseTime=true",
213213
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
214214
}
215215
case "postgres":

models/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Notification struct {
4545
Source NotificationSource `xorm:"SMALLINT INDEX NOT NULL"`
4646

4747
IssueID int64 `xorm:"INDEX NOT NULL"`
48-
CommitID string `xorm:"INDEX"`
48+
CommitID string `xorm:"VARCHAR(191) INDEX"`
4949

5050
UpdatedBy int64 `xorm:"INDEX NOT NULL"`
5151

models/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Release struct {
2525
Repo *Repository `xorm:"-"`
2626
PublisherID int64 `xorm:"INDEX"`
2727
Publisher *User `xorm:"-"`
28-
TagName string `xorm:"INDEX UNIQUE(n)"`
28+
TagName string `xorm:"VARCHAR(191) INDEX UNIQUE(n)"`
2929
LowerTagName string
3030
Target string
3131
Title string

models/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ type Repository struct {
165165
OwnerID int64 `xorm:"UNIQUE(s)"`
166166
OwnerName string `xorm:"-"`
167167
Owner *User `xorm:"-"`
168-
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
169-
Name string `xorm:"INDEX NOT NULL"`
168+
LowerName string `xorm:"VARCHAR(191) UNIQUE(s) INDEX NOT NULL"`
169+
Name string `xorm:"VARCHAR(191) INDEX NOT NULL"`
170170
Description string
171171
Website string
172172
DefaultBranch string

models/repo_redirect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "strings"
1010
type RepoRedirect struct {
1111
ID int64 `xorm:"pk autoincr"`
1212
OwnerID int64 `xorm:"UNIQUE(s)"`
13-
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
13+
LowerName string `xorm:"VARCHAR(191) UNIQUE(s) INDEX NOT NULL"`
1414
RedirectRepoID int64 // repoID to redirect to
1515
}
1616

models/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ var (
7676
// User represents the object of individual and member of organization.
7777
type User struct {
7878
ID int64 `xorm:"pk autoincr"`
79-
LowerName string `xorm:"UNIQUE NOT NULL"`
80-
Name string `xorm:"UNIQUE NOT NULL"`
79+
LowerName string `xorm:"VARCHAR(191) UNIQUE NOT NULL"`
80+
Name string `xorm:"VARCHAR(191) UNIQUE NOT NULL"`
8181
FullName string
8282
// Email is the primary email address (to be used for communication)
8383
Email string `xorm:"NOT NULL"`

models/user_mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
type EmailAddress struct {
2121
ID int64 `xorm:"pk autoincr"`
2222
UID int64 `xorm:"INDEX NOT NULL"`
23-
Email string `xorm:"UNIQUE NOT NULL"`
23+
Email string `xorm:"VARCHAR(191) UNIQUE NOT NULL"`
2424
IsActivated bool
2525
IsPrimary bool `xorm:"-"`
2626
}

models/user_openid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
type UserOpenID struct {
2121
ID int64 `xorm:"pk autoincr"`
2222
UID int64 `xorm:"INDEX NOT NULL"`
23-
URI string `xorm:"UNIQUE NOT NULL"`
23+
URI string `xorm:"VARCHAR(191) UNIQUE NOT NULL"`
2424
Show bool `xorm:"DEFAULT false"`
2525
}
2626

0 commit comments

Comments
 (0)