2021-08-06 17:21:50 +03:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2021-08-06 18:17:06 +03:00
|
|
|
"fmt"
|
2021-08-06 17:21:50 +03:00
|
|
|
"github.com/emvi/logbuch"
|
|
|
|
"github.com/muety/wakapi/config"
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
const name = "20210806-remove_persisted_project_labels"
|
|
|
|
f := migrationFunc{
|
|
|
|
name: name,
|
|
|
|
f: func(db *gorm.DB, cfg *config.Config) error {
|
2021-12-15 12:50:16 +03:00
|
|
|
if hasRun(name, db) {
|
2021-08-06 17:21:50 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
rawDb, err := db.DB()
|
|
|
|
if err != nil {
|
|
|
|
logbuch.Error("failed to retrieve raw sql db instance")
|
|
|
|
return err
|
|
|
|
}
|
2021-08-06 18:17:06 +03:00
|
|
|
if _, err := rawDb.Exec(fmt.Sprintf("delete from summary_items where type = %d", models.SummaryLabel)); err != nil {
|
2021-08-06 17:21:50 +03:00
|
|
|
logbuch.Error("failed to delete project label summary items")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logbuch.Info("successfully deleted project label summary items")
|
|
|
|
|
2021-12-15 12:50:16 +03:00
|
|
|
setHasRun(name, db)
|
2021-08-06 17:21:50 +03:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
registerPostMigration(f)
|
|
|
|
}
|