Class: OpenC3::UpdatedAtToInt
- Defined in:
- lib/openc3/migrations/20260701000000_updated_at_to_int.rb
Overview
Earlier versions of the Python script runner wrote the ScriptStatusModel updated_at field as an ISO8601 string (e.g. "2026-06-30T12:34:56.789012Z") instead of integer nanoseconds since the epoch. This migration rewrites any such string values as integers so updated_at is consistently an int.
NOTE: The stored JSON is edited in place rather than reloaded through the model and re-created, because ScriptStatusModel#create always sets updated_at to the current time, which would discard the original timestamp.
Class Method Summary collapse
Class Method Details
.run ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/openc3/migrations/20260701000000_updated_at_to_int.rb', line 30 def self.run ScopeModel.names.each do |scope| [ScriptStatusModel::RUNNING_PRIMARY_KEY, ScriptStatusModel::COMPLETED_PRIMARY_KEY].each do |key| primary_key = "#{key}__#{scope}" Store.hgetall(primary_key).each do |name, json| data = JSON.parse(json, allow_nan: true) updated_at = data['updated_at'] next unless updated_at.is_a?(String) begin data['updated_at'] = Time.parse(updated_at).to_nsec_from_epoch rescue ArgumentError # Leave unparsable values untouched next end Store.hset(primary_key, name, JSON.generate(data, allow_nan: true)) end end end end |