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 errortokarchuk/v1.17
parent
d3c5911ffc
commit
c06cc740de
@ -1,57 +0,0 @@ |
||||
// 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/git" |
||||
"code.gitea.io/gitea/models" |
||||
"code.gitea.io/gitea/modules/log" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
// ReleaseV39 describes the added field for Release
|
||||
type ReleaseV39 struct { |
||||
IsTag bool `xorm:"NOT NULL DEFAULT false"` |
||||
} |
||||
|
||||
// TableName will be invoked by XORM to customrize the table name
|
||||
func (*ReleaseV39) TableName() string { |
||||
return "release" |
||||
} |
||||
|
||||
func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error { |
||||
if err := x.Sync2(new(ReleaseV39)); err != nil { |
||||
return fmt.Errorf("Sync2: %v", err) |
||||
} |
||||
|
||||
// For the sake of SQLite3, we can't use x.Iterate here.
|
||||
offset := 0 |
||||
pageSize := 20 |
||||
for { |
||||
repos := make([]*models.Repository, 0, pageSize) |
||||
if err := x.Table("repository").Asc("id").Limit(pageSize, offset).Find(&repos); err != nil { |
||||
return fmt.Errorf("select repos [offset: %d]: %v", offset, err) |
||||
} |
||||
for _, repo := range repos { |
||||
gitRepo, err := git.OpenRepository(repo.RepoPath()) |
||||
if err != nil { |
||||
log.Warn("OpenRepository: %v", err) |
||||
continue |
||||
} |
||||
|
||||
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil { |
||||
log.Warn("SyncReleasesWithTags: %v", err) |
||||
} |
||||
} |
||||
if len(repos) < pageSize { |
||||
break |
||||
} |
||||
offset += pageSize |
||||
} |
||||
return nil |
||||
} |
@ -1,26 +0,0 @@ |
||||
// 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" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
func fixProtectedBranchCanPushValue(x *xorm.Engine) error { |
||||
type ProtectedBranch struct { |
||||
CanPush bool `xorm:"NOT NULL DEFAULT false"` |
||||
} |
||||
|
||||
if err := x.Sync2(new(ProtectedBranch)); err != nil { |
||||
return fmt.Errorf("Sync2: %v", err) |
||||
} |
||||
|
||||
_, err := x.Cols("can_push").Update(&ProtectedBranch{ |
||||
CanPush: false, |
||||
}) |
||||
return err |
||||
} |
@ -1,69 +0,0 @@ |
||||
// 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" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
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) |
||||
} |
||||
|
||||
sess := x.NewSession() |
||||
defer sess.Close() |
||||
|
||||
if err := sess.Begin(); err != nil { |
||||
return err |
||||
} |
||||
|
||||
for _, repoUnit := range externalIssueRepoUnits { |
||||
if _, err = sess.Delete(&RepoUnit{ |
||||
RepoID: repoUnit.RepoID, |
||||
Type: UnitTypeIssues, |
||||
}); err != nil { |
||||
return fmt.Errorf("Delete repo unit: %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 sess.Commit() |
||||
} |
@ -0,0 +1,42 @@ |
||||
// 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 ( |
||||
"code.gitea.io/gitea/models" |
||||
"code.gitea.io/gitea/modules/log" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
func addDefaultValueToUserProhibitLogin(x *xorm.Engine) (err error) { |
||||
user := &models.User{ |
||||
ProhibitLogin: false, |
||||
} |
||||
|
||||
if _, err := x.Where("`prohibit_login` IS NULL").Cols("prohibit_login").Update(user); 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": |
||||
} |
||||
|
||||
if err != nil { |
||||
// Ignoring this error in case we run this migration second time (after migration reordering)
|
||||
log.Warn("Error changing user prohibit_login column definition (skipping): %v", err) |
||||
} |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,31 @@ |
||||
// 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" |
||||
"time" |
||||
|
||||
"code.gitea.io/gitea/models" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
func addLFSLock(x *xorm.Engine) error { |
||||
// LFSLock see models/lfs_lock.go
|
||||
type LFSLock struct { |
||||
ID int64 `xorm:"pk autoincr"` |
||||
RepoID int64 `xorm:"INDEX NOT NULL"` |
||||
Owner *models.User `xorm:"-"` |
||||
OwnerID int64 `xorm:"INDEX NOT NULL"` |
||||
Path string `xorm:"TEXT"` |
||||
Created time.Time `xorm:"created"` |
||||
} |
||||
|
||||
if err := x.Sync2(new(LFSLock)); err != nil { |
||||
return fmt.Errorf("Sync2: %v", err) |
||||
} |
||||
return nil |
||||
} |
@ -0,0 +1,28 @@ |
||||
// 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" |
||||
|
||||
"github.com/go-xorm/xorm" |
||||
) |
||||
|
||||
func addReactions(x *xorm.Engine) error { |
||||
// Reaction see models/issue_reaction.go
|
||||
type Reaction struct { |
||||
ID int64 `xorm:"pk autoincr"` |
||||
Type string `xorm:"INDEX UNIQUE(s) NOT NULL"` |
||||
IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` |
||||
CommentID int64 `xorm:"INDEX UNIQUE(s)"` |
||||
UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` |
||||
CreatedUnix int64 `xorm:"INDEX created"` |
||||
} |
||||
|
||||
if err := x.Sync2(new(Reaction)); err != nil { |
||||
return fmt.Errorf("Sync2: %v", err) |
||||
} |
||||
return nil |
||||
} |
Loading…
Reference in new issue