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