-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix wrong type on hooktask to convert typ from char(16) to varchar(16) #14148
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
abd3ca8
Fix wrong type on hooktask to convert typ from char(16) to varchar(16)
lunny 5cb1ec2
Fix bugs
lunny 19d2a6b
Improve code
lunny 6bb67aa
Use different trim function for MSSQL
lunny a895e03
Fix bug
lunny ef2fb77
Removed wrong changed line
lunny 4516d70
Removed wrong changed line
lunny afebd2f
Fix nullable
lunny c30dbd8
Fix lint
lunny b400816
Ignore sqlite on migration
lunny 1343067
Fix mssql modify column failure
lunny 7fd394d
Move modifyColumn to migrations.go so that other migrate function cou…
lunny 726b7e8
Merge branch 'master' into lunny/fix_webhook
6543 b2de9dd
Merge branch 'master' into lunny/fix_webhook
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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" | ||
lafriks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"xorm.io/xorm/schemas" | ||
) | ||
|
||
func convertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error { | ||
dbType := x.Dialect().URI().DBType | ||
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT | ||
lafriks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
} | ||
|
||
type HookTask struct { | ||
Typ string `xorm:"VARCHAR(16) index"` | ||
} | ||
|
||
if err := modifyColumn(x, "hook_task", &schemas.Column{ | ||
Name: "typ", | ||
SQLType: schemas.SQLType{ | ||
Name: "VARCHAR", | ||
}, | ||
Length: 16, | ||
Nullable: true, // To keep compatible as nullable | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
var hookTaskTrimSQL string | ||
if dbType == schemas.MSSQL { | ||
hookTaskTrimSQL = "UPDATE hook_task SET typ = RTRIM(LTRIM(typ))" | ||
} else { | ||
hookTaskTrimSQL = "UPDATE hook_task SET typ = TRIM(typ)" | ||
} | ||
if _, err := x.Exec(hookTaskTrimSQL); err != nil { | ||
return err | ||
} | ||
|
||
type Webhook struct { | ||
Type string `xorm:"VARCHAR(16) index"` | ||
} | ||
|
||
if err := modifyColumn(x, "webhook", &schemas.Column{ | ||
Name: "type", | ||
SQLType: schemas.SQLType{ | ||
Name: "VARCHAR", | ||
}, | ||
Length: 16, | ||
Nullable: true, // To keep compatible as nullable | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
var webhookTrimSQL string | ||
if dbType == schemas.MSSQL { | ||
webhookTrimSQL = "UPDATE webhook SET type = RTRIM(LTRIM(type))" | ||
} else { | ||
webhookTrimSQL = "UPDATE webhook SET type = TRIM(type)" | ||
} | ||
_, err := x.Exec(webhookTrimSQL) | ||
return err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.