Skip to content

Commit bc45588

Browse files
GiteaBotlunnysilverwind
authored
Remove If Exist check on migration for mssql because that syntax required SQL server 2016 (#30894) (#30946)
Backport #30894 by @lunny Fix #30872 We will assume the database is consistent before executing the migration. So the indexes should exist. Removing `IF EXIST` then is safe enough. Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent 14dc00a commit bc45588

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
-
22
id: 1
3+
user_id: 1
4+
pull_id: 1
35
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d

models/migrations/v1_22/v286.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
3636
if setting.Database.Type.IsMSSQL() {
3737
// drop indexes that need to be re-created afterwards
3838
droppedIndexes := []string{
39-
"DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]",
40-
"DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON [review_state]",
41-
"DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]",
39+
"DROP INDEX [IDX_commit_status_context_hash] ON [commit_status]",
40+
"DROP INDEX [UQE_review_state_pull_commit_user] ON [review_state]",
41+
"DROP INDEX [UQE_repo_archiver_s] ON [repo_archiver]",
4242
}
4343
for _, s := range droppedIndexes {
4444
_, err := db.Exec(s)

models/migrations/v1_22/v286_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) {
1919

2020
type CommitStatus struct {
2121
ID int64
22-
ContextHash string
22+
ContextHash string `xorm:"char(40) index"`
2323
}
2424

2525
type RepoArchiver struct {
2626
ID int64
27-
RepoID int64
28-
Type int
29-
CommitID string
27+
RepoID int64 `xorm:"index unique(s)"`
28+
Type int `xorm:"unique(s)"`
29+
CommitID string `xorm:"VARCHAR(40) unique(s)"`
3030
}
3131

3232
type ReviewState struct {
3333
ID int64
34-
CommitSHA string
35-
UserID int64
36-
PullID int64
34+
UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"`
35+
PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"`
36+
CommitSHA string `xorm:"NOT NULL VARCHAR(40) UNIQUE(pull_commit_user)"`
3737
}
3838

3939
type Comment struct {

0 commit comments

Comments
 (0)