Class: OpenC3::ActivityUuid

Inherits:
Migration show all
Defined in:
lib/openc3/migrations/20240915000000_activity_uuid.rb

Class Method Summary collapse

Class Method Details

.runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openc3/migrations/20240915000000_activity_uuid.rb', line 7

def self.run
  ScopeModel.names.each do |scope|
    TimelineModel.names.each do |key|
      name = key.split('__').last
      json = Store.zrange("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", 0, -1)
      parsed = json.map { |value| JSON.parse(value, :allow_nan => true, :create_additions => true) }
      parsed.each_with_index do |activity, index|
        if activity['uuid'].nil?
          activity['uuid'] = SecureRandom.uuid
          Store.zrem("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", json[index])
          Store.zadd("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", activity['start'], JSON.generate(activity))
        end
      end
    end
  end
end