jovandeginste / workout-tracker

A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities
Other
945 stars 31 forks source link

Add postgresql support #92

Closed icewind1991 closed 5 months ago

icewind1991 commented 5 months ago
jovandeginste commented 5 months ago

Thank you for your contribution! I'm not sure why you changed the max function in the SQL queries; they were necessary...?

jovandeginste commented 5 months ago

It would be cleaner to move the strings to separate functions (on statConfig), taking the db name as a parameter. If other exceptions would be added, the code is better contained...

icewind1991 commented 5 months ago

It would be cleaner to move the strings to separate functions (on statConfig), taking the db name as a parameter. If other exceptions would be added, the code is better contained...

Done

Thank you for your contribution! I'm not sure why you changed the max function in the SQL queries; they were necessary...?

I misunderstood the workouts <-> map_data relation to be 1-1.

From the code I'm not sure if the records logic was working previously, as there didn't seem to be any logic to make the selected workout id and date match the selected value. I've changed the records query to sort on the value so it returns the correct id and date.

jovandeginste commented 5 months ago

To be clear, the workout <-> map_data relation SHOULD BE 1-1, but because of an error in my code (which should be fixed), this was not always the case... I'll add cleanup code to fix problems in the database too.

jovandeginste commented 5 months ago

The cleanup and enforcement of the relation should be fixed in #102

jovandeginste commented 5 months ago

I tested the code, and the sqlite part works as before; there are two more styling issues to be solved (I run the tests locally), if you don't mind fixing them:

pkg/database/gorm.go:109:7: string `postgres` has 4 occurrences, make it a constant (goconst)
    case "postgres":
         ^
pkg/database/workouts.go:34: File is not `gofmt`-ed with `-s` (gofmt)
    GPXData  []byte `gorm:"type:text" json:"-"` // To be removed
    Filename string `json:"-"`                        // To be removed
    Checksum []byte `gorm:"default:'legacy'" json:"-"`  // To be removed
icewind1991 commented 5 months ago

should be fixed now

jovandeginste commented 5 months ago

should be fixed now

Correct, all green for me - I'll let the github action run.

jovandeginste commented 5 months ago

Thank you so much, also for your patience with my questions!

Thovi98 commented 5 months ago

Wow nice thanks! Is there a way to migrate from an sqlite instance?

jovandeginste commented 5 months ago

There are tools that help switch between database techs...