The old migration had a few issues:
- It left old column names around
- It did not give the right access levels for owners and admins
Also, this includes a migration that fixes the authorization of owner teams, which was previously ORG_ADMIN (instead of ORG_OWNER)
if_,err:=x.Exec("UPDATE team SET authorize=4 WHERE lower_name=?","owners");err!=nil{
returnfmt.Errorf("drop table: %v",err)
}
returnnil
}
funcaccessRefactor(x*xorm.Engine)(errerror){
funcaccessRefactor(x*xorm.Engine)(errerror){
type(
type(
AccessModeint
AccessModeint
Accessstruct{
Accessstruct{
IDint64`xorm:"pk autoincr"`
UserNamestring
RepoNamestring
UserIDint64`xorm:"UNIQUE(s)"`
RepoIDint64`xorm:"UNIQUE(s)"`
ModeAccessMode
IDint64`xorm:"pk autoincr"`
UserIDint64`xorm:"UNIQUE(s)"`
RepoIDint64`xorm:"UNIQUE(s)"`
ModeAccessMode
}
UserRepostruct{
UserIDint64
RepoIDint64
}
}
)
)
varrawSQLstring
switch{
casesetting.UseSQLite3,setting.UsePostgreSQL:
rawSQL="DROP INDEX IF EXISTS `UQE_access_S`"
casesetting.UseMySQL:
rawSQL="DROP INDEX `UQE_access_S` ON `access`"
}
if_,err=x.Exec(rawSQL);err!=nil&&
!strings.Contains(err.Error(),"check that column/key exists"){
returnfmt.Errorf("drop index: %v",err)
}
// We consiously don't start a session yet as we make only reads for now, no writes
sess:=x.NewSession()
defersessionRelease(sess)
iferr=sess.Begin();err!=nil{
accessMap:=make(map[UserRepo]AccessMode,50)
results,err:=x.Query("SELECT r.id as `repo_id`, r.is_private as `is_private`, r.owner_id as `owner_id`, u.type as `owner_type` FROM `repository` r LEFT JOIN user u ON r.owner_id=u.id")