Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL data types need to be refactored #13

Open
alexanderfefelov opened this issue Oct 18, 2020 · 4 comments
Open

MySQL data types need to be refactored #13

alexanderfefelov opened this issue Oct 18, 2020 · 4 comments

Comments

@alexanderfefelov
Copy link

  • dl, ul, ping, jitter are numbers, not a text,
  • text and longtext are too big data types,
  • nullability requires more attention.

Environment

  • speedtest-go 1.1.1

Links

alexanderfefelov added a commit to alexanderfefelov/docker-backpack that referenced this issue Oct 18, 2020
@maddie
Copy link
Collaborator

maddie commented Nov 6, 2020

Sorry for the late reply, I've been held up by work lately.

I agree that the data types aren't quite accurate, but I'm not really sure that I'd want to implement this change now, because:

  1. It would break current users if the Go code changes (types aren't compatible)
  2. It's working fine for now (well...)
  3. I can't really think of the difference between using text and numbers if we're just "showing them in the stats page", and if one wants to use the numbers for statistical use, there are still a lot of ways to write simple code to parse the string into numbers

I'll leave it open for now, but implementing this change is very unlikely in the near future. Maybe in v2?

@alexanderfefelov
Copy link
Author

Ping and co generates numerical data by nature. Using numerical data allows the LibreSpeed database to be treated as a time series database without any additional coding.

@maddie
Copy link
Collaborator

maddie commented Nov 6, 2020

Yes, I understand, but in the code:

func (p *MySQL) Insert(data *schema.TelemetryData) error {
stmt := `INSERT INTO speedtest_users (ip, ispinfo, extra, ua, lang, dl, ul, ping, jitter, log, uuid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
_, err := p.db.Exec(stmt, data.IPAddress, data.ISPInfo, data.Extra, data.UserAgent, data.Language, data.Download, data.Upload, data.Ping, data.Jitter, data.Log, data.UUID)
return err
}
func (p *MySQL) FetchByUUID(uuid string) (*schema.TelemetryData, error) {
var record schema.TelemetryData
row := p.db.QueryRow(`SELECT * FROM speedtest_users WHERE uuid = ?`, uuid)
if row != nil {
var id string
if err := row.Scan(&id, &record.Timestamp, &record.IPAddress, &record.ISPInfo, &record.Extra, &record.UserAgent, &record.Language, &record.Download, &record.Upload, &record.Ping, &record.Jitter, &record.Log, &record.UUID); err != nil {
return nil, err
}
}
return &record, nil
}

... fields in schema.TelemetryData are all strings. If this change is to be implemented, users with old schemas will not be able to insert/load records, unless they recreate the database. This would qualify as a breaking change.

@Enrico204
Copy link
Contributor

This might be fixed with a migration: the code can detect this change at runtime and ask the user to migrate (or automatically migrate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants