Class: OpenC3::AddTargetNames

Inherits:
Migration show all
Defined in:
lib/openc3/migrations/20221202214600_add_target_names.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
# File 'lib/openc3/migrations/20221202214600_add_target_names.rb', line 6

def self.run
  ScopeModel.names.each do |scope|
    # Get all existing InterfaceModels and add cmd_target_names / tlm_target_names if necessary
    interface_models = InterfaceModel.all(scope: scope)
    interface_models.each do |key, model_hash|
      target_names = model_hash['target_names']
      model_hash['cmd_target_names'] = target_names unless model_hash['cmd_target_names']
      model_hash['tlm_target_names'] = target_names unless model_hash['tlm_target_names']
      InterfaceModel.from_json(model_hash, scope: scope).update
    end
    router_models = RouterModel.all(scope: scope)
    router_models.each do |key, model_hash|
      target_names = model_hash['target_names']
      model_hash['cmd_target_names'] = target_names unless model_hash['cmd_target_names']
      model_hash['tlm_target_names'] = target_names unless model_hash['tlm_target_names']
      RouterModel.from_json(model_hash, scope: scope).update
    end
  end
end