From b23fdaa6dc30fcfa862e5d855404fe0bb8108dea Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:29:56 +0200 Subject: [PATCH] Fix registry migration (#3871) --- .../migration/032_registries_add_user.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/store/datastore/migration/032_registries_add_user.go b/server/store/datastore/migration/032_registries_add_user.go index df8d29eb6..4329d6861 100644 --- a/server/store/datastore/migration/032_registries_add_user.go +++ b/server/store/datastore/migration/032_registries_add_user.go @@ -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 }