Fix registry migration (#3871)

This commit is contained in:
Anbraten 2024-07-04 10:29:56 +02:00 committed by GitHub
parent e118f8d980
commit b23fdaa6dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,13 +15,32 @@
package migration
import (
"fmt"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)
type registryV032 struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'repo_id'"`
Address string `json:"address" xorm:"UNIQUE(s) INDEX 'address'"`
Username string `json:"username" xorm:"varchar(2000) 'username'"`
Password string `json:"password" xorm:"TEXT 'password'"`
}
func (r registryV032) TableName() string {
return "registries"
}
var alterTableRegistriesFixRequiredFields = xormigrate.Migration{
ID: "alter-table-registries-fix-required-fields",
MigrateSession: func(sess *xorm.Session) error {
// make sure old registry exists
if err := sess.Sync(new(registryV032)); err != nil {
return fmt.Errorf("sync models failed: %w", err)
}
if err := alterColumnDefault(sess, "registries", "repo_id", "0"); err != nil {
return err
}