summaryrefslogtreecommitdiffstats
path: root/models/migrations/v41.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-12-13 16:52:18 +0200
committerGitHub <noreply@github.com>2017-12-13 16:52:18 +0200
commitc06cc740dea46f3aff58e0eded4208232bb5902d (patch)
tree8f17cf90828fb06133a14cdee2df67ea6db75550 /models/migrations/v41.go
parentd3c5911ffce8758d020b301e667869aa2e80ce6a (diff)
downloadgitea-c06cc740dea46f3aff58e0eded4208232bb5902d.tar.gz
gitea-c06cc740dea46f3aff58e0eded4208232bb5902d.zip
Reorder migrations, skip errors if running migration again (#3160)
* Reorder migrations, skip errors if running migration again * Rename migration file names to match migration version * Add note about ingored error
Diffstat (limited to 'models/migrations/v41.go')
-rw-r--r--models/migrations/v41.go67
1 files changed, 47 insertions, 20 deletions
diff --git a/models/migrations/v41.go b/models/migrations/v41.go
index 89763c3afe..4de3ad4e99 100644
--- a/models/migrations/v41.go
+++ b/models/migrations/v41.go
@@ -7,36 +7,63 @@ package migrations
import (
"fmt"
- "code.gitea.io/gitea/models"
-
"github.com/go-xorm/xorm"
)
-func addDefaultValueToUserProhibitLogin(x *xorm.Engine) (err error) {
- user := &models.User{
- ProhibitLogin: false,
+func removeDuplicateUnitTypes(x *xorm.Engine) error {
+ // RepoUnit describes all units of a repository
+ type RepoUnit struct {
+ RepoID int64
+ Type int
+ }
+
+ // Enumerate all the unit types
+ const (
+ UnitTypeCode = iota + 1 // 1 code
+ UnitTypeIssues // 2 issues
+ UnitTypePullRequests // 3 PRs
+ UnitTypeReleases // 4 Releases
+ UnitTypeWiki // 5 Wiki
+ UnitTypeExternalWiki // 6 ExternalWiki
+ UnitTypeExternalTracker // 7 ExternalTracker
+ )
+
+ var externalIssueRepoUnits []RepoUnit
+ err := x.Where("type = ?", UnitTypeExternalTracker).Find(&externalIssueRepoUnits)
+ if err != nil {
+ return fmt.Errorf("Query repositories: %v", err)
+ }
+
+ var externalWikiRepoUnits []RepoUnit
+ err = x.Where("type = ?", UnitTypeExternalWiki).Find(&externalWikiRepoUnits)
+ if err != nil {
+ return fmt.Errorf("Query repositories: %v", err)
}
- if _, err := x.Where("`prohibit_login` IS NULL").Cols("prohibit_login").Update(user); err != nil {
+ sess := x.NewSession()
+ defer sess.Close()
+
+ if err := sess.Begin(); err != nil {
return err
}
- dialect := x.Dialect().DriverName()
-
- switch dialect {
- case "mysql":
- _, err = x.Exec("ALTER TABLE user MODIFY `prohibit_login` tinyint(1) NOT NULL DEFAULT 0")
- case "postgres":
- _, err = x.Exec("ALTER TABLE \"user\" ALTER COLUMN `prohibit_login` SET NOT NULL, ALTER COLUMN `prohibit_login` SET DEFAULT false")
- case "mssql":
- // xorm already set DEFAULT 0 for data type BIT in mssql
- _, err = x.Exec(`ALTER TABLE [user] ALTER COLUMN "prohibit_login" BIT NOT NULL`)
- case "sqlite3":
+ for _, repoUnit := range externalIssueRepoUnits {
+ if _, err = sess.Delete(&RepoUnit{
+ RepoID: repoUnit.RepoID,
+ Type: UnitTypeIssues,
+ }); err != nil {
+ return fmt.Errorf("Delete repo unit: %v", err)
+ }
}
- if err != nil {
- return fmt.Errorf("Error changing user prohibit_login column definition: %v", err)
+ for _, repoUnit := range externalWikiRepoUnits {
+ if _, err = sess.Delete(&RepoUnit{
+ RepoID: repoUnit.RepoID,
+ Type: UnitTypeWiki,
+ }); err != nil {
+ return fmt.Errorf("Delete repo unit: %v", err)
+ }
}
- return err
+ return sess.Commit()
}