Module: SkullIsland::Helpers::Migration

Included in:
CLI
Defined in:
lib/skull_island/helpers/migration.rb

Overview

Simple helper methods for migrating old configs

Instance Method Summary collapse

Instance Method Details

#migrate_0_14_to_1_1(config) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/skull_island/helpers/migration.rb', line 15

def migrate_0_14_to_1_1(config)
  new_config = config.dup
  config['plugins']&.each_with_index do |plugin, plugin_index|
    %w[consumer route service].each do |rtype|
      if plugin["#{rtype}_id"]&.start_with?('<%=')
        new_config['plugins'][plugin_index][rtype] = plugin["#{rtype}_id"].dup
        new_config['plugins'][plugin_index].delete("#{rtype}_id")
      elsif plugin["#{rtype}_id"]
        new_config['plugins'][plugin_index][rtype] = {
          'id' => plugin["#{rtype}_id"].dup
        }
      end
    end
  end
  new_config['version'] = '1.1'
  new_config
end

#migrate_config(config) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/skull_island/helpers/migration.rb', line 7

def migrate_config(config)
  if config['version'] == '0.14'
    migrate_0_14_to_1_1(config)
  else
    false # Just return false if it can't be migrated
  end
end