Skip to content

Commit 2f10bfa

Browse files
guillep2klafriks
authored andcommitted
Fix extra columns from label table (#8633)
* Fix extra fields from database * Add migration to drop unneeded columns * Fix lint * Make sure the columns exist
1 parent 3fe9646 commit 2f10bfa

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

models/issue_label.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ type Label struct {
6868
Color string `xorm:"VARCHAR(7)"`
6969
NumIssues int
7070
NumClosedIssues int
71-
NumOpenIssues int `xorm:"-"`
72-
IsChecked bool `xorm:"-"`
73-
QueryString string
74-
IsSelected bool
71+
NumOpenIssues int `xorm:"-"`
72+
IsChecked bool `xorm:"-"`
73+
QueryString string `xorm:"-"`
74+
IsSelected bool `xorm:"-"`
7575
}
7676

7777
// APIFormat converts a Label to the api.Label format

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ var migrations = []Migration{
262262
NewMigration("update migration repositories' service type", dropColumnHeadUserNameOnPullRequest),
263263
// v103 -> v104
264264
NewMigration("Add WhitelistDeployKeys to protected branch", addWhitelistDeployKeysToBranches),
265+
// v104 -> v105
266+
NewMigration("remove unnecessary columns from label", removeLabelUneededCols),
265267
}
266268

267269
// Migrate database to current version

models/migrations/v104.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func removeLabelUneededCols(x *xorm.Engine) error {
12+
13+
// Make sure the columns exist before dropping them
14+
type Label struct {
15+
QueryString string
16+
IsSelected bool
17+
}
18+
if err := x.Sync2(new(Label)); err != nil {
19+
return err
20+
}
21+
22+
sess := x.NewSession()
23+
defer sess.Close()
24+
if err := sess.Begin(); err != nil {
25+
return err
26+
}
27+
if err := dropTableColumns(sess, "label", "query_string"); err != nil {
28+
return err
29+
}
30+
if err := dropTableColumns(sess, "label", "is_selected"); err != nil {
31+
return err
32+
}
33+
return sess.Commit()
34+
}

0 commit comments

Comments
 (0)