Sha256: 75100dde9ae50119f17c5be2451f56a1d128d783252742386a0a4e940ed7bd5d

Contents?: true

Size: 1.43 KB

Versions: 27

Compression:

Stored size: 1.43 KB

Contents

require 'openc3/utilities/migration'
require 'openc3/models/scope_model'

module OpenC3
  class LogStuff < Migration
    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
  end
end

unless ENV['OPENC3_NO_MIGRATE']
  OpenC3::LogStuff.run
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
openc3-5.20.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.19.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.18.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.17.1 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.17.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.16.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.15.2 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.15.1 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.15.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.14.2 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.14.1 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.14.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.13.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.12.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.11.3 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.11.2 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.11.1 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.11.0 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.10.1 lib/openc3/migrations/20220420190000_log_stuff.rb
openc3-5.10.0 lib/openc3/migrations/20220420190000_log_stuff.rb