mirror of https://github.com/gogs/gogs.git
Change data model. Rename repository.pulls_allow_rebase to repository.pulls_allow_alt, and add repository.pulls_prefer_rebase.
parent
46a84fdad5
commit
33ba8f74f4
|
@ -63,6 +63,10 @@ var migrations = []Migration{
|
|||
// on v22. Let's make a noop v22 to make sure every instance will not miss a
|
||||
// real future migration.
|
||||
NewMigration("noop", func(*gorm.DB) error { return nil }),
|
||||
NewMigration(
|
||||
"rename repository.pulls_allow_rebase -> repository.pulls_allow_alt",
|
||||
renameRepoPullsAllowRebaseToPullsAllowAlt,
|
||||
),
|
||||
}
|
||||
|
||||
var errMigrationSkipped = errors.New("the migration has been skipped")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2025 The Gogs Authors. 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 (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func renameRepoPullsAllowRebaseToPullsAllowAlt(db *gorm.DB) error {
|
||||
type Repository struct {
|
||||
PullsAllowRebase bool `gorm:"not null;default:FALSE"`
|
||||
PullsAllowAlt bool `gorm:"not null;default:FALSE"`
|
||||
}
|
||||
if db.Migrator().HasColumn(&Repository{}, "PullsAllowAlt") {
|
||||
return errMigrationSkipped
|
||||
}
|
||||
return db.Migrator().RenameColumn(&Repository{}, "PullsAllowRebase", "PullsAllowAlt")
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2025 The Gogs Authors. 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 (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"gogs.io/gogs/internal/dbtest"
|
||||
)
|
||||
|
||||
type repositoryPreV22 struct {
|
||||
PullsAllowRebase bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
}
|
||||
|
||||
func (*repositoryPreV22) TableName() string {
|
||||
return "repository"
|
||||
}
|
||||
|
||||
type repositoryV22 struct {
|
||||
PullsAllowAlt bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
}
|
||||
|
||||
func (*repositoryV22) TableName() string {
|
||||
return "repository"
|
||||
}
|
||||
|
||||
func TestRenameRepoPullsAllowRebaseToPullsAllowAlt(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
db := dbtest.NewDB(t, "renamePullsAllowRebaseToPullsAllowAlt", new(repositoryPreV22))
|
||||
err := db.Create(
|
||||
&repositoryPreV22{
|
||||
PullsAllowRebase: false,
|
||||
},
|
||||
).Error
|
||||
require.NoError(t, err)
|
||||
assert.False(t, db.Migrator().HasColumn(&repositoryV22{}, "PullsAllowAlt"))
|
||||
assert.True(t, db.Migrator().HasColumn(&repositoryPreV22{}, "PullsAllowRebase"))
|
||||
|
||||
err = renameRepoPullsAllowRebaseToPullsAllowAlt(db)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, db.Migrator().HasColumn(&repositoryV22{}, "PullsAllowAlt"))
|
||||
assert.False(t, db.Migrator().HasColumn(&repositoryPreV22{}, "PullsAllowRebase"))
|
||||
|
||||
// Re-run should be skipped
|
||||
err = renameRepoPullsAllowRebaseToPullsAllowAlt(db)
|
||||
require.Equal(t, errMigrationSkipped, err)
|
||||
}
|
|
@ -201,7 +201,8 @@ type Repository struct {
|
|||
ExternalMetas map[string]string `xorm:"-" gorm:"-" json:"-"`
|
||||
EnablePulls bool `xorm:"NOT NULL DEFAULT true" gorm:"not null;default:TRUE"`
|
||||
PullsIgnoreWhitespace bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
PullsAllowRebase bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
PullsPreferRebase bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
PullsAllowAlt bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
|
||||
IsFork bool `xorm:"NOT NULL DEFAULT false" gorm:"not null;default:FALSE"`
|
||||
ForkID int64
|
||||
|
|
Loading…
Reference in New Issue