Skip to content

Commit

Permalink
Convert original_author_id column data type to numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit189 committed Jun 19, 2024
1 parent e610a6e commit 0fd6466
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ var migrations = []Migration{
// v299 -> v300
NewMigration("Add content version to issue and comment table", v1_23.AddContentVersionToIssueAndComment),
// v300 -> v301
NewMigration("Chnage original_author_id of issue, comments, release, reaction and review table to accomodate OAuth2 UserId", v1_23.changeOriginalAuthorIDDataTypeToNumeric),
NewMigration("Convert original_author_id of issue, comments, release, reaction and review table to numeric", v1_23.ConvertAuthorIDToNumeric),
}

// GetCurrentDBVersion returns the current db version
Expand Down
19 changes: 12 additions & 7 deletions models/migrations/v1_23/v300.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ package v1_23 //nolint
import (
"strings"

"code.gitea.io/gitea/modules/setting"
"xorm.io/xorm"
)

func changeOriginalAuthorIDDataTypeToNumeric(x *xorm.Engine) error {
func ConvertAuthorIDToNumeric(x *xorm.Engine) error {
// Google OAuth2 provider may give very long user IDs
if !setting.Database.Type.IsPostgreSQL() {
return nil
}
sql := strings.Join([]string{
"ALTER TABLE `issue` ALTER COLUMN `original_author_id` TYPE NUMERIC USING `original_author_id`::NUMERIC",
"ALTER TABLE `comment` ALTER COLUMN `original_author_id` TYPE NUMERIC USING `original_author_id`::NUMERIC",
"ALTER TABLE `release` ALTER COLUMN `original_author_id` TYPE NUMERIC USING `original_author_id`::NUMERIC",
"ALTER TABLE `reaction` ALTER COLUMN `original_author_id` TYPE NUMERIC USING `original_author_id`::NUMERIC",
"ALTER TABLE `review` ALTER COLUMN `original_author_id` TYPE NUMERIC USING `original_author_id`::NUMERIC",
}, "; ")
"ALTER TABLE issue ALTER COLUMN original_author_id TYPE NUMERIC USING original_author_id::NUMERIC;",
"ALTER TABLE comment ALTER COLUMN original_author_id TYPE NUMERIC USING original_author_id::NUMERIC;",
"ALTER TABLE release ALTER COLUMN original_author_id TYPE NUMERIC USING original_author_id::NUMERIC;",
"ALTER TABLE reaction ALTER COLUMN original_author_id TYPE NUMERIC USING original_author_id::NUMERIC;",
"ALTER TABLE review ALTER COLUMN original_author_id TYPE NUMERIC USING original_author_id::NUMERIC;",
}, " ")

_, err := x.Exec(sql)
return err
Expand Down

0 comments on commit 0fd6466

Please sign in to comment.