diff --git a/db/migrate/20260629000001_fix_probe_result_duration_precision.rb b/db/migrate/20260629000001_fix_probe_result_duration_precision.rb new file mode 100644 index 0000000..c7490a8 --- /dev/null +++ b/db/migrate/20260629000001_fix_probe_result_duration_precision.rb @@ -0,0 +1,14 @@ +class FixProbeResultDurationPrecision < ActiveRecord::Migration[8.0] + # `t.decimal :duration` with no precision becomes DECIMAL(10,0) on MySQL, + # which rounds every duration to a whole second on write. Probe durations + # are sub-second floats from a monotonic clock, so they were all stored as + # 0. SQLite preserved the fractional value, which is why this only surfaced + # after the MySQL migration. Give the column microsecond precision. + def up + change_column :upright_probe_results, :duration, :decimal, precision: 10, scale: 6 + end + + def down + change_column :upright_probe_results, :duration, :decimal + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index c671aa7..6c06c3e 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2025_01_14_000001) do +ActiveRecord::Schema[8.1].define(version: 2026_06_29_000001) do create_table "active_storage_attachments", force: :cascade do |t| t.bigint "blob_id", null: false t.datetime "created_at", null: false @@ -41,7 +41,7 @@ create_table "upright_probe_results", force: :cascade do |t| t.datetime "created_at", null: false - t.decimal "duration" + t.decimal "duration", precision: 10, scale: 6 t.string "probe_name" t.string "probe_service" t.string "probe_target"