74399f333f
* Rewrite migrations to not depend on future code changes (#2604) * v38 migration used an outdated version of RepoUnit model (#2602) * change repoUnit model in migration * fix v16 migration repo_unit table * fix lint error * move type definition inside function * Fix migration from Gogs * Refactor code * add error check * Additiomal fixes for migrations * Add back nil check * replace deprecated .Id with .ID Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * change string map to interface map Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
25 lines
665 B
Go
25 lines
665 B
Go
// Copyright 2016 Gitea. 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 createAllowCreateOrganizationColumn(x *xorm.Engine) error {
|
|
type User struct {
|
|
KeepEmailPrivate bool
|
|
AllowCreateOrganization bool
|
|
}
|
|
|
|
if err := x.Sync2(new(User)); err != nil {
|
|
return fmt.Errorf("Sync2: %v", err)
|
|
} else if _, err = x.Where("`type` = 0").Cols("allow_create_organization").Update(&User{AllowCreateOrganization: true}); err != nil {
|
|
return fmt.Errorf("set allow_create_organization: %v", err)
|
|
}
|
|
return nil
|
|
}
|