migrations fix

This commit is contained in:
Pavel 2020-01-10 09:45:08 +03:00
parent c2efcc6f10
commit 17c2dfa1e7
2 changed files with 7 additions and 7 deletions

View file

@ -1,8 +1,6 @@
package migrations
import (
"errors"
"github.com/jinzhu/gorm"
"github.com/retailcrm/mg-transport-core/core"
"gopkg.in/gormigrate.v1"
@ -13,13 +11,17 @@ func init() {
ID: "1577785798",
Migrate: func(db *gorm.DB) error {
if db.HasTable("schema_migrations") {
return db.DropTable("schema_migrations").Error
return db.Exec("ALTER TABLE schema_migrations RENAME TO schema_migrations_old;").Error
}
return nil
},
Rollback: func(db *gorm.DB) error {
return errors.New("this migration cannot be rolled back")
if db.HasTable("schema_migrations_old") {
return db.Exec("ALTER TABLE schema_migrations_old RENAME TO schema_migrations;").Error
}
return nil
},
})
}

View file

@ -1,8 +1,6 @@
package migrations
import (
"errors"
"github.com/jinzhu/gorm"
"github.com/retailcrm/mg-bot-helper/src/models"
"github.com/retailcrm/mg-transport-core/core"
@ -16,7 +14,7 @@ func init() {
return db.AutoMigrate(models.Connection{}).Error
},
Rollback: func(db *gorm.DB) error {
return errors.New("this migration cannot be rolled back")
return nil
},
})
}