diff --git a/models/login_source.go b/models/login_source.go index 88ad42dc5..03d3af6d3 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -131,7 +131,7 @@ func (f *AuthSourceFile) Save() error { type LoginSource struct { ID int64 Type LoginType - Name string `xorm:"UNIQUE"` + Name string `xorm:"varchar(191) UNIQUE"` IsActived bool `xorm:"NOT NULL DEFAULT false"` Cfg core.Conversion `xorm:"TEXT"` diff --git a/models/models.go b/models/models.go index 6407f4134..b80f9c36b 100644 --- a/models/models.go +++ b/models/models.go @@ -330,6 +330,7 @@ func ImportDatabase(dirPath string, verbose bool) (err error) { rawTableName := x.TableName(table) _, isInsertProcessor := table.(xorm.BeforeInsertProcessor) scanner := bufio.NewScanner(f) + for scanner.Scan() { switch bean := table.(type) { case *LoginSource: @@ -367,8 +368,11 @@ func ImportDatabase(dirPath string, verbose bool) (err error) { // Reset created_unix back to the date save in archive because Insert method updates its value if isInsertProcessor && !skipInsertProcessors[rawTableName] { - if _, err = x.Exec("UPDATE "+rawTableName+" SET created_unix=? WHERE id=?", meta["CreatedUnix"], meta["ID"]); err != nil { - log.Error(2, "Failed to reset 'created_unix': %v", err) + timestamp, ok := meta["CreatedUnix"].(uint64) + if ok { + if _, err = x.Exec("UPDATE "+rawTableName+" SET created_unix=? WHERE id=?", timestamp, meta["ID"]); err != nil { + log.Error(2, "Failed to reset 'created_unix': %v", err) + } } } diff --git a/models/repo.go b/models/repo.go index c9c1964ae..68659d653 100644 --- a/models/repo.go +++ b/models/repo.go @@ -152,7 +152,7 @@ type Repository struct { ID int64 OwnerID int64 `xorm:"UNIQUE(s)"` Owner *User `xorm:"-" json:"-"` - LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` + LowerName string `xorm:"varchar(191) UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` Description string `xorm:"VARCHAR(512)"` Website string diff --git a/models/repo_branch.go b/models/repo_branch.go index 1d98fd12a..b080d8c5a 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -70,7 +70,7 @@ type ProtectBranchWhitelist struct { ID int64 ProtectBranchID int64 RepoID int64 `xorm:"UNIQUE(protect_branch_whitelist)"` - Name string `xorm:"UNIQUE(protect_branch_whitelist)"` + Name string `xorm:"varchar(191) UNIQUE(protect_branch_whitelist)"` UserID int64 `xorm:"UNIQUE(protect_branch_whitelist)"` } @@ -84,7 +84,7 @@ func IsUserInProtectBranchWhitelist(repoID, userID int64, branch string) bool { type ProtectBranch struct { ID int64 RepoID int64 `xorm:"UNIQUE(protect_branch)"` - Name string `xorm:"UNIQUE(protect_branch)"` + Name string `xorm:"varchar(191) UNIQUE(protect_branch)"` Protected bool RequirePullRequest bool EnableWhitelist bool diff --git a/models/user.go b/models/user.go index 7e014df43..6e7eda319 100644 --- a/models/user.go +++ b/models/user.go @@ -48,8 +48,8 @@ const ( // User represents the object of individual and member of organization. type User struct { ID int64 - LowerName string `xorm:"UNIQUE NOT NULL"` - Name string `xorm:"UNIQUE NOT NULL"` + LowerName string `xorm:"varchar(191) UNIQUE NOT NULL"` + Name string `xorm:"varchar(191) UNIQUE NOT NULL"` FullName string // Email is the primary email address (to be used for communication) Email string `xorm:"NOT NULL"` diff --git a/models/user_mail.go b/models/user_mail.go index 46197490f..2231c000c 100644 --- a/models/user_mail.go +++ b/models/user_mail.go @@ -16,7 +16,7 @@ import ( type EmailAddress struct { ID int64 UID int64 `xorm:"INDEX NOT NULL"` - Email string `xorm:"UNIQUE NOT NULL"` + Email string `xorm:"varchar(191) UNIQUE NOT NULL"` IsActivated bool IsPrimary bool `xorm:"-" json:"-"` }