Class: OpenC3::LogStuff

Inherits:
Migration show all
Defined in:
lib/openc3/migrations/20220420190000_log_stuff.rb

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openc3/migrations/20220420190000_log_stuff.rb', line 6

def self.run
  ScopeModel.names.each do |scope|
    # Get all existing InterfaceModels and change json for log_raw to log_stream
    # Also remove the log key
    interface_models = InterfaceModel.all(scope: scope)
    interface_models.each do |key, model_hash|
      if model_hash.has_key?('log_raw')
        if model_hash['log_raw']
          model_hash['log_stream'] = []
        else
          model_hash['log_stream'] = nil
        end
        if model_hash.has_key?('log')
          model_hash.delete('log')
        end
        model_hash.delete('log_raw')
        InterfaceModel.from_json(model_hash, scope: scope).update
      end
    end
    router_models = RouterModel.all(scope: scope)
    router_models.each do |key, model_hash|
      if model_hash.has_key?('log_raw')
        if model_hash['log_raw']
          model_hash['log_stream'] = []
        else
          model_hash['log_stream'] = nil
        end
        if model_hash.has_key?('log')
          model_hash.delete('log')
        end
        model_hash.delete('log_raw')
        RouterModel.from_json(model_hash, scope: scope).update
      end
    end
  end
end