Skip to content

Commit

Permalink
feat(database): Add pre-migration cleanup actions
Browse files Browse the repository at this point in the history
This commit introduces pre-migration cleanup actions to ensure data integrity.

It removes map data details associated with map data IDs that have an
earlier creation date, eliminating potential inconsistencies in map data
details.
  • Loading branch information
jovandeginste committed Nov 12, 2024
1 parent 6d65746 commit 96a96c0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/database/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ func preMigrationActions(db *gorm.DB) error {
q = db.
Where("id < (select max(id) from workouts as w where w.date = workouts.date and w.user_id = workouts.user_id)").
Delete(&Workout{})
if q.Error != nil {
return q.Error
}

q = db.
Where("map_data_id IN (SELECT map_data_id FROM map_data_details as mdd where map_data_details.created_at < mdd.created_at)").
Delete(&MapDataDetails{})

return q.Error
}
Expand Down

0 comments on commit 96a96c0

Please sign in to comment.