Bläddra i källkod

Remove repo unit index (#2621)

* Remove repo unit index

* Fix sqlite
tags/v1.3.0-rc1
Morlinest 6 år sedan
förälder
incheckning
a04718a2a6

+ 0
- 10
models/fixtures/repo_unit.yml Visa fil

id: 1 id: 1
repo_id: 1 repo_id: 1
type: 4 type: 4
index: 3
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 2 id: 2
repo_id: 1 repo_id: 1
type: 5 type: 5
index: 4
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 3 id: 3
repo_id: 1 repo_id: 1
type: 1 type: 1
index: 0
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 4 id: 4
repo_id: 1 repo_id: 1
type: 2 type: 2
index: 1
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}"
created_unix: 946684810 created_unix: 946684810


id: 5 id: 5
repo_id: 1 repo_id: 1
type: 3 type: 3
index: 2
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 6 id: 6
repo_id: 3 repo_id: 3
type: 1 type: 1
index: 0
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 7 id: 7
repo_id: 3 repo_id: 3
type: 2 type: 2
index: 1
config: "{\"EnableTimetracker\":false,\"AllowOnlyContributorsToTrackTime\":false}" config: "{\"EnableTimetracker\":false,\"AllowOnlyContributorsToTrackTime\":false}"
created_unix: 946684810 created_unix: 946684810


id: 8 id: 8
repo_id: 3 repo_id: 3
type: 3 type: 3
index: 2
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 9 id: 9
repo_id: 3 repo_id: 3
type: 4 type: 4
index: 3
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810


id: 10 id: 10
repo_id: 3 repo_id: 3
type: 5 type: 5
index: 4
config: "{}" config: "{}"
created_unix: 946684810 created_unix: 946684810

+ 2
- 0
models/migrations/migrations.go Visa fil

NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue), NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
// v44 -> v45 // v44 -> v45
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes), NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
// v45 -> v46
NewMigration("remove index column from repo_unit table", removeIndexColumnFromRepoUnitTable),
} }


// Migrate database to current version // Migrate database to current version

+ 28
- 0
models/migrations/v45.go Visa fil

// Copyright 2017 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 (
"fmt"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
)

func removeIndexColumnFromRepoUnitTable(x *xorm.Engine) (err error) {
switch {
case setting.UseSQLite3:
log.Warn("Unable to drop columns in SQLite")
case setting.UseMySQL, setting.UsePostgreSQL, setting.UseMSSQL, setting.UseTiDB:
if _, err := x.Exec("ALTER TABLE repo_unit DROP COLUMN index"); err != nil {
return fmt.Errorf("DROP COLUMN index: %v", err)
}
default:
log.Fatal(4, "Unrecognized DB")
}

return nil
}

+ 1
- 3
models/repo.go Visa fil



// insert units for repo // insert units for repo
var units = make([]RepoUnit, 0, len(defaultRepoUnits)) var units = make([]RepoUnit, 0, len(defaultRepoUnits))
for i, tp := range defaultRepoUnits {
for _, tp := range defaultRepoUnits {
if tp == UnitTypeIssues { if tp == UnitTypeIssues {
units = append(units, RepoUnit{ units = append(units, RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: tp, Type: tp,
Index: i,
Config: &IssuesConfig{EnableTimetracker: setting.Service.DefaultEnableTimetracking, AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime}, Config: &IssuesConfig{EnableTimetracker: setting.Service.DefaultEnableTimetracking, AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime},
}) })
} else { } else {
units = append(units, RepoUnit{ units = append(units, RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: tp, Type: tp,
Index: i,
}) })
} }



+ 2
- 3
models/repo_unit.go Visa fil

// RepoUnit describes all units of a repository // RepoUnit describes all units of a repository
type RepoUnit struct { type RepoUnit struct {
ID int64 ID int64
RepoID int64 `xorm:"INDEX(s)"`
Type UnitType `xorm:"INDEX(s)"`
Index int
RepoID int64 `xorm:"INDEX(s)"`
Type UnitType `xorm:"INDEX(s)"`
Config core.Conversion `xorm:"TEXT"` Config core.Conversion `xorm:"TEXT"`
CreatedUnix int64 `xorm:"INDEX CREATED"` CreatedUnix int64 `xorm:"INDEX CREATED"`
Created time.Time `xorm:"-"` Created time.Time `xorm:"-"`

+ 0
- 6
routers/repo/setting.go Visa fil

units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: tp, Type: tp,
Index: int(tp),
Config: new(models.UnitConfig), Config: new(models.UnitConfig),
}) })
} }
units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: models.UnitTypeExternalWiki, Type: models.UnitTypeExternalWiki,
Index: int(models.UnitTypeExternalWiki),
Config: &models.ExternalWikiConfig{ Config: &models.ExternalWikiConfig{
ExternalWikiURL: form.ExternalWikiURL, ExternalWikiURL: form.ExternalWikiURL,
}, },
units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: models.UnitTypeWiki, Type: models.UnitTypeWiki,
Index: int(models.UnitTypeWiki),
Config: new(models.UnitConfig), Config: new(models.UnitConfig),
}) })
} }
units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: models.UnitTypeExternalTracker, Type: models.UnitTypeExternalTracker,
Index: int(models.UnitTypeExternalTracker),
Config: &models.ExternalTrackerConfig{ Config: &models.ExternalTrackerConfig{
ExternalTrackerURL: form.ExternalTrackerURL, ExternalTrackerURL: form.ExternalTrackerURL,
ExternalTrackerFormat: form.TrackerURLFormat, ExternalTrackerFormat: form.TrackerURLFormat,
units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: models.UnitTypeIssues, Type: models.UnitTypeIssues,
Index: int(models.UnitTypeIssues),
Config: &models.IssuesConfig{ Config: &models.IssuesConfig{
EnableTimetracker: form.EnableTimetracker, EnableTimetracker: form.EnableTimetracker,
AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime, AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
units = append(units, models.RepoUnit{ units = append(units, models.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: models.UnitTypePullRequests, Type: models.UnitTypePullRequests,
Index: int(models.UnitTypePullRequests),
Config: new(models.UnitConfig), Config: new(models.UnitConfig),
}) })
} }

Laddar…
Avbryt
Spara