Skip to content

Reorder migrations, skip errors if running migration again #3160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type Version struct {
Version int64
}

func emptyMigtation(x *xorm.Engine) error {
return nil
}

// This is a sequence of migrations. Add new migrations to the bottom of the list.
// If you want to "retire" a migration, remove it from the top of the list and
// update minDBVersion accordingly
Expand Down Expand Up @@ -127,17 +131,17 @@ var migrations = []Migration{
// v38 -> v39
NewMigration("remove commits and settings unit types", removeCommitsUnitType),
// v39 -> v40
NewMigration("adds time tracking and stopwatches", addTimetracking),
NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags),
// v40 -> v41
NewMigration("migrate protected branch struct", migrateProtectedBranchStruct),
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
// v41 -> v42
NewMigration("add default value to user prohibit_login", addDefaultValueToUserProhibitLogin),
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
// v42 -> v43
NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags),
NewMigration("empty step", emptyMigtation),
// v43 -> v44
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
NewMigration("empty step", emptyMigtation),
// v44 -> v45
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
NewMigration("empty step", emptyMigtation),
// v45 -> v46
NewMigration("remove index column from repo_unit table", removeIndexColumnFromRepoUnitTable),
// v46 -> v47
Expand All @@ -147,8 +151,14 @@ var migrations = []Migration{
// v48 -> v49
NewMigration("add repo indexer status", addRepoIndexerStatus),
// v49 -> v50
NewMigration("add lfs lock table", addLFSLock),
NewMigration("adds time tracking and stopwatches", addTimetracking),
// v50 -> v51
NewMigration("migrate protected branch struct", migrateProtectedBranchStruct),
// v51 -> v52
NewMigration("add default value to user prohibit_login", addDefaultValueToUserProhibitLogin),
// v52 -> v53
NewMigration("add lfs lock table", addLFSLock),
// v53 -> v54
NewMigration("add reactions", addReactions),
}

Expand Down
5 changes: 2 additions & 3 deletions models/migrations/v39.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ func addTimetracking(x *xorm.Engine) error {
// RepoUnit describes all units of a repository
type RepoUnit struct {
ID int64
RepoID int64 `xorm:"INDEX(s)"`
Type int `xorm:"INDEX(s)"`
Index int
RepoID int64 `xorm:"INDEX(s)"`
Type int `xorm:"INDEX(s)"`
Config map[string]interface{} `xorm:"JSON"`
CreatedUnix int64 `xorm:"INDEX CREATED"`
Created time.Time `xorm:"-"`
Expand Down
3 changes: 1 addition & 2 deletions models/migrations/v40.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package migrations

import (
"fmt"
"time"

"code.gitea.io/gitea/modules/log"
Expand Down Expand Up @@ -45,7 +44,7 @@ func migrateProtectedBranchStruct(x *xorm.Engine) error {
log.Warn("Unable to drop columns in SQLite")
case setting.UseMySQL, setting.UsePostgreSQL, setting.UseMSSQL, setting.UseTiDB:
if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
return fmt.Errorf("DROP COLUMN can_push: %v", err)
log.Warn("DROP COLUMN can_push (skipping): %v", err)
}
default:
log.Fatal(4, "Unrecognized DB")
Expand Down
7 changes: 3 additions & 4 deletions models/migrations/v41.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package migrations

import (
"fmt"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"

"github.com/go-xorm/xorm"
)
Expand Down Expand Up @@ -35,8 +34,8 @@ func addDefaultValueToUserProhibitLogin(x *xorm.Engine) (err error) {
}

if err != nil {
return fmt.Errorf("Error changing user prohibit_login column definition: %v", err)
log.Warn("Error changing user prohibit_login column definition (skipping): %v", err)
}

return err
return nil
}
5 changes: 2 additions & 3 deletions models/migrations/v45.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package migrations

import (
"fmt"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

"github.com/go-xorm/xorm"
)

Expand All @@ -18,7 +17,7 @@ func removeIndexColumnFromRepoUnitTable(x *xorm.Engine) (err error) {
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)
log.Warn("DROP COLUMN index: %v", err)
}
default:
log.Fatal(4, "Unrecognized DB")
Expand Down