mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
31 lines
738 B
Go
31 lines
738 B
Go
|
package migrations
|
||
|
|
||
|
import (
|
||
|
"github.com/emvi/logbuch"
|
||
|
"github.com/muety/wakapi/config"
|
||
|
"github.com/muety/wakapi/models"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
func hasRun(name string, db *gorm.DB) bool {
|
||
|
condition := "key = ?"
|
||
|
if config.Get().Db.Dialect == config.SQLDialectMysql {
|
||
|
condition = "`key` = ?"
|
||
|
}
|
||
|
lookupResult := db.Where(condition, name).First(&models.KeyStringValue{})
|
||
|
if lookupResult.Error == nil && lookupResult.RowsAffected > 0 {
|
||
|
logbuch.Info("no need to migrate '%s'", name)
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func setHasRun(name string, db *gorm.DB) {
|
||
|
if err := db.Create(&models.KeyStringValue{
|
||
|
Key: name,
|
||
|
Value: "done",
|
||
|
}).Error; err != nil {
|
||
|
logbuch.Error("failed to mark migration %s as run - %v", name, err)
|
||
|
}
|
||
|
}
|