summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-01-30 20:47:11 +0100
committerGitHub <noreply@github.com>2021-01-30 21:47:11 +0200
commit446c06b81794a7f71d2890812d0d9ff8b044395e (patch)
tree09bd4faa1fca0f4869880f1e56561731e52cd2d0
parent9569607abbcf7aee7d8353dc1ff32c9116081851 (diff)
downloadgitea-446c06b81794a7f71d2890812d0d9ff8b044395e.tar.gz
gitea-446c06b81794a7f71d2890812d0d9ff8b044395e.zip
Set the name Mapper in migrations (#14526) (#14529)
Migrations currently uses the default Xorm mapper which is not the same as the mapper Gitea actually uses. This means that there is a difference between the struct parsing and mapping to database tables in migrations as compared to normal Sync2. This was the cause for the catastrophic problem in v168 - untagged fields are not mapped in the same way in migrations as compared to outside of migrations. This is also likely the cause of some weird subtle failures in other migrations as any untagged field may not be being mapped exactly the same way. This PR suggests that we ensure that the mapper is set at the start of the migrations code - but also enforces a strict clean mapper between each migration. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
-rw-r--r--models/migrations/migrations.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 0efcce30a9..5cb85cc18c 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"xorm.io/xorm"
+ "xorm.io/xorm/names"
)
const minDBVersion = 70 // Gitea 1.5.3
@@ -296,6 +297,8 @@ func EnsureUpToDate(x *xorm.Engine) error {
// Migrate database to current version
func Migrate(x *xorm.Engine) error {
+ // Set a new clean the default mapper to GonicMapper as that is the default for Gitea.
+ x.SetMapper(names.GonicMapper{})
if err := x.Sync(new(Version)); err != nil {
return fmt.Errorf("sync: %v", err)
}
@@ -334,6 +337,8 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
// Migrate
for i, m := range migrations[v-minDBVersion:] {
log.Info("Migration[%d]: %s", v+int64(i), m.Description())
+ // Reset the mapper between each migration - migrations are not supposed to depend on each other
+ x.SetMapper(names.GonicMapper{})
if err = m.Migrate(x); err != nil {
return fmt.Errorf("do migrate: %v", err)
}