mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
fix migrations for fresh databases
This commit is contained in:
parent
d516d74d3f
commit
cadbe4a090
@ -117,7 +117,15 @@ func MigrateDatabase(db *gorm.DB, version string) error {
|
|||||||
db.Order("applied desc, version desc").FirstOrInit(&lastVersion)
|
db.Order("applied desc, version desc").FirstOrInit(&lastVersion)
|
||||||
|
|
||||||
if lastVersion.Version == "" {
|
if lastVersion.Version == "" {
|
||||||
return nil // no previous version exists, no migrations to apply
|
// fresh database, no migrations to apply
|
||||||
|
res := db.Create(&DatabaseMigrationInfo{
|
||||||
|
Version: version,
|
||||||
|
Applied: time.Now(),
|
||||||
|
})
|
||||||
|
if res.Error != nil {
|
||||||
|
return errors.Wrapf(res.Error, "failed to write version %s to database", version)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(migrations, func(i, j int) bool {
|
sort.Slice(migrations, func(i, j int) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user