Skip to content

Restrict some tables' columns size #14075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/issue_reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v159.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
27 changes: 27 additions & 0 deletions models/migrations/v168.go
Original file line number Diff line number Diff line change
@@ -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))
}
4 changes: 2 additions & 2 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down