Skip to content

Commit eff2b8f

Browse files
committed
Remove repo unit index
1 parent 26e49b8 commit eff2b8f

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

models/fixtures/repo_unit.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,68 @@
22
id: 1
33
repo_id: 1
44
type: 1
5-
index: 0
65
config: "{}"
76
created_unix: 946684810
87

98
-
109
id: 2
1110
repo_id: 1
1211
type: 2
13-
index: 1
1412
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}"
1513
created_unix: 946684810
1614

1715
-
1816
id: 3
1917
repo_id: 1
2018
type: 3
21-
index: 2
2219
config: "{}"
2320
created_unix: 946684810
2421

2522
-
2623
id: 4
2724
repo_id: 1
2825
type: 4
29-
index: 3
3026
config: "{}"
3127
created_unix: 946684810
3228

3329
-
3430
id: 5
3531
repo_id: 1
3632
type: 5
37-
index: 4
3833
config: "{}"
3934
created_unix: 946684810
4035

4136
-
4237
id: 6
4338
repo_id: 3
4439
type: 1
45-
index: 0
4640
config: "{}"
4741
created_unix: 946684810
4842

4943
-
5044
id: 7
5145
repo_id: 3
5246
type: 2
53-
index: 1
5447
config: "{\"EnableTimetracker\":false,\"AllowOnlyContributorsToTrackTime\":false}"
5548
created_unix: 946684810
5649

5750
-
5851
id: 8
5952
repo_id: 3
6053
type: 3
61-
index: 2
6254
config: "{}"
6355
created_unix: 946684810
6456

6557
-
6658
id: 9
6759
repo_id: 3
6860
type: 4
69-
index: 3
7061
config: "{}"
7162
created_unix: 946684810
7263

7364
-
7465
id: 10
7566
repo_id: 3
7667
type: 5
77-
index: 4
7868
config: "{}"
7969
created_unix: 946684810

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ var migrations = []Migration{
138138
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
139139
// v44 -> v45
140140
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
141+
// v45 -> v46
142+
NewMigration("remove index column from repo_unit table", removeIndexColumnFromRepoUnitTable),
141143
}
142144

143145
// Migrate database to current version

models/migrations/v45.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
"fmt"
9+
10+
"github.com/go-xorm/xorm"
11+
)
12+
13+
func removeIndexColumnFromRepoUnitTable(x *xorm.Engine) (err error) {
14+
if _, err := x.Exec("ALTER TABLE repo_unit DROP COLUMN index"); err != nil {
15+
return fmt.Errorf("DROP COLUMN index: %v", err)
16+
}
17+
return nil
18+
}

models/repo.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,19 +1252,17 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
12521252

12531253
// insert units for repo
12541254
var units = make([]RepoUnit, 0, len(defaultRepoUnits))
1255-
for i, tp := range defaultRepoUnits {
1255+
for _, tp := range defaultRepoUnits {
12561256
if tp == UnitTypeIssues {
12571257
units = append(units, RepoUnit{
12581258
RepoID: repo.ID,
12591259
Type: tp,
1260-
Index: i,
12611260
Config: &IssuesConfig{EnableTimetracker: setting.Service.DefaultEnableTimetracking, AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime},
12621261
})
12631262
} else {
12641263
units = append(units, RepoUnit{
12651264
RepoID: repo.ID,
12661265
Type: tp,
1267-
Index: i,
12681266
})
12691267
}
12701268

models/repo_unit.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616
// RepoUnit describes all units of a repository
1717
type RepoUnit struct {
1818
ID int64
19-
RepoID int64 `xorm:"INDEX(s)"`
20-
Type UnitType `xorm:"INDEX(s)"`
21-
Index int
19+
RepoID int64 `xorm:"INDEX(s)"`
20+
Type UnitType `xorm:"INDEX(s)"`
2221
Config core.Conversion `xorm:"TEXT"`
2322
CreatedUnix int64 `xorm:"INDEX CREATED"`
2423
Created time.Time `xorm:"-"`

routers/repo/setting.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
149149
units = append(units, models.RepoUnit{
150150
RepoID: repo.ID,
151151
Type: tp,
152-
Index: int(tp),
153152
Config: new(models.UnitConfig),
154153
})
155154
}
@@ -165,7 +164,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
165164
units = append(units, models.RepoUnit{
166165
RepoID: repo.ID,
167166
Type: models.UnitTypeExternalUncyclo,
168-
Index: int(models.UnitTypeExternalUncyclo),
169167
Config: &models.ExternalUncycloConfig{
170168
ExternalUncycloURL: form.ExternalUncycloURL,
171169
},
@@ -174,7 +172,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
174172
units = append(units, models.RepoUnit{
175173
RepoID: repo.ID,
176174
Type: models.UnitTypeUncyclo,
177-
Index: int(models.UnitTypeUncyclo),
178175
Config: new(models.UnitConfig),
179176
})
180177
}
@@ -190,7 +187,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
190187
units = append(units, models.RepoUnit{
191188
RepoID: repo.ID,
192189
Type: models.UnitTypeExternalTracker,
193-
Index: int(models.UnitTypeExternalTracker),
194190
Config: &models.ExternalTrackerConfig{
195191
ExternalTrackerURL: form.ExternalTrackerURL,
196192
ExternalTrackerFormat: form.TrackerURLFormat,
@@ -201,7 +197,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
201197
units = append(units, models.RepoUnit{
202198
RepoID: repo.ID,
203199
Type: models.UnitTypeIssues,
204-
Index: int(models.UnitTypeIssues),
205200
Config: &models.IssuesConfig{
206201
EnableTimetracker: form.EnableTimetracker,
207202
AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
@@ -214,7 +209,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
214209
units = append(units, models.RepoUnit{
215210
RepoID: repo.ID,
216211
Type: models.UnitTypePullRequests,
217-
Index: int(models.UnitTypePullRequests),
218212
Config: new(models.UnitConfig),
219213
})
220214
}

0 commit comments

Comments
 (0)