From 3e839ea85adaff9e644d0c982a3ab245b3217a95 Mon Sep 17 00:00:00 2001 From: Jo Vandeginste Date: Sun, 4 Aug 2024 15:12:15 +0200 Subject: [PATCH] chore: remove legacy attributes Also remove the code that converted them. Signed-off-by: Jo Vandeginste --- pkg/database/gorm.go | 3 +- pkg/database/gorm_convert.go | 68 ------------------------------------ pkg/database/workouts.go | 5 --- pkg/database/workouts_map.go | 2 -- 4 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 pkg/database/gorm_convert.go diff --git a/pkg/database/gorm.go b/pkg/database/gorm.go index 7682bd88..5eb137fe 100644 --- a/pkg/database/gorm.go +++ b/pkg/database/gorm.go @@ -86,7 +86,8 @@ func preMigrationActions(db *gorm.DB) error { } func postMigrationActions(db *gorm.DB) error { - return convertWorkouts(db) + // Nothing to do for now + return nil } func setUserAPIKeys(db *gorm.DB) error { diff --git a/pkg/database/gorm_convert.go b/pkg/database/gorm_convert.go deleted file mode 100644 index 0f3e4504..00000000 --- a/pkg/database/gorm_convert.go +++ /dev/null @@ -1,68 +0,0 @@ -package database - -import ( - "context" - "fmt" - - "gorm.io/gorm" -) - -func convertWorkouts(db *gorm.DB) error { - workouts, err := GetWorkouts(db.Preload("Data").Preload("GPX").Where("LENGTH(gpx_data) > 0 or data IS NOT NULL")) - if err != nil { - return err - } - - for _, w := range workouts { - db.Logger.Info(context.Background(), fmt.Sprintf("Converting workout gpx data: %d", w.ID)) - - if w.GPXData != nil { - if err := convertGPXData(db, w); err != nil { - return err - } - } - - if w.MapData != nil { - if err := convertMapData(db, w); err != nil { - return err - } - } - - if err := w.Save(db); err != nil { - return err - } - } - - return nil -} - -func convertGPXData(db *gorm.DB, w *Workout) error { - w.GPX = &GPXData{ - WorkoutID: w.ID, - Content: w.GPXData, - Filename: w.Filename, - Checksum: w.Checksum, - } - w.GPXData = nil - - return w.GPX.Save(db) -} - -func convertMapData(db *gorm.DB, w *Workout) error { - w.Data = w.MapData - w.Data.WorkoutID = w.ID - w.MapData = nil - - if w.Data.Points == nil { - return w.Data.Save(db) - } - - w.Data.Details.Points = w.Data.Points - w.Data.Points = nil - - if err := w.Data.Details.Save(db); err != nil { - return err - } - - return w.Data.Save(db) -} diff --git a/pkg/database/workouts.go b/pkg/database/workouts.go index cd458cf7..7b286c97 100644 --- a/pkg/database/workouts.go +++ b/pkg/database/workouts.go @@ -31,11 +31,6 @@ type Workout struct { Data *MapData `json:",omitempty"` // The map data associated with the workout GPX *GPXData `json:",omitempty"` // The file data associated with the workout Equipment []Equipment `json:",omitempty" gorm:"many2many:workout_equipment"` // Which equipment is used for this workout - - MapData *MapData `gorm:"serializer:json;column:data" json:"-"` // To be removed - GPXData []byte `gorm:"type:text" json:"-"` // To be removed - Filename string `json:"-"` // To be removed - Checksum []byte `gorm:"default:'legacy'" json:"-"` // To be removed } type GPXData struct { diff --git a/pkg/database/workouts_map.go b/pkg/database/workouts_map.go index 03c48dcf..7086f6be 100644 --- a/pkg/database/workouts_map.go +++ b/pkg/database/workouts_map.go @@ -71,8 +71,6 @@ type MapData struct { Details *MapDataDetails `json:",omitempty"` // The details of the workout TotalRepetitions int // The number of repetitions of the workout TotalWeight float64 // The weight of the workout - - Points []MapPoint `gorm:"serializer:json" json:"-"` // To be removed } type MapDataDetails struct {