mirror of https://github.com/gogs/gogs.git
db: skip auto migrate for existing "version" table (#7057)
parent
c0db4a7f1b
commit
4a3dc6c774
|
@ -96,8 +96,9 @@ func Init(w logger.Writer) (*gorm.DB, error) {
|
|||
panic("unreachable")
|
||||
}
|
||||
|
||||
// NOTE: GORM has problem detecting existing columns, see https://github.com/gogs/gogs/issues/6091.
|
||||
// Therefore only use it to create new tables, and do customized migration with future changes.
|
||||
// NOTE: GORM has problem detecting existing columns, see
|
||||
// https://github.com/gogs/gogs/issues/6091. Therefore only use it to create new
|
||||
// tables, and do customized migration with future changes.
|
||||
for _, table := range Tables {
|
||||
if db.Migrator().HasTable(table) {
|
||||
continue
|
||||
|
|
|
@ -58,13 +58,17 @@ var migrations = []Migration{
|
|||
|
||||
// Migrate migrates the database schema and/or data to the current version.
|
||||
func Migrate(db *gorm.DB) error {
|
||||
err := db.AutoMigrate(new(Version))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `auto migrate "version" table`)
|
||||
// NOTE: GORM has problem migrating tables that happen to have columns with the
|
||||
// same name, see https://github.com/gogs/gogs/issues/7056.
|
||||
if !db.Migrator().HasTable(new(Version)) {
|
||||
err := db.AutoMigrate(new(Version))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `auto migrate "version" table`)
|
||||
}
|
||||
}
|
||||
|
||||
var current Version
|
||||
err = db.Where("id = ?", 1).First(¤t).Error
|
||||
err := db.Where("id = ?", 1).First(¤t).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
err = db.Create(
|
||||
&Version{
|
||||
|
|
Loading…
Reference in New Issue