mirror of
https://github.com/muety/wakapi.git
synced 2025-12-05 22:20:24 -08:00
38 lines
778 B
Go
38 lines
778 B
Go
package migrations
|
|
|
|
import (
|
|
"github.com/muety/wakapi/config"
|
|
"github.com/muety/wakapi/models"
|
|
"github.com/muety/wakapi/utils"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
func init() {
|
|
const name = "20210411-add_imprint_content"
|
|
f := migrationFunc{
|
|
name: name,
|
|
f: func(db *gorm.DB, cfg *config.Config) error {
|
|
if hasRun(name, db) {
|
|
return nil
|
|
}
|
|
|
|
condition := utils.QuoteSql(db, "%s = ?", "key")
|
|
|
|
imprintKv := &models.KeyStringValue{Key: "imprint", Value: "no content here"}
|
|
if err := db.
|
|
Clauses(clause.OnConflict{UpdateAll: false, DoNothing: true}).
|
|
Where(condition, imprintKv.Key).
|
|
Assign(imprintKv).
|
|
Create(imprintKv).Error; err != nil {
|
|
return err
|
|
}
|
|
|
|
setHasRun(name, db)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
registerPostMigration(f)
|
|
}
|