speedtest-go icon indicating copy to clipboard operation
speedtest-go copied to clipboard

MySQL data types need to be refactored

Open alexanderfefelov opened this issue 5 years ago • 4 comments

  • 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

  • https://github.com/librespeed/speedtest-go/blob/master/database/mysql/telemetry_mysql.sql
  • https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-strings

alexanderfefelov avatar Oct 18 '20 04:10 alexanderfefelov

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?

maddie avatar Nov 06 '20 17:11 maddie

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.

alexanderfefelov avatar Nov 06 '20 18:11 alexanderfefelov

Yes, I understand, but in the code:

https://github.com/librespeed/speedtest-go/blob/c815103e20b0f090ee8973866bc85ffafe8dc0c1/database/mysql/mysql.go#L30-L46

... 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.

maddie avatar Nov 06 '20 18:11 maddie

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

Enrico204 avatar Dec 10 '20 19:12 Enrico204