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



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

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_1_1_to_1_4(config) ⇒ Object



35
36
37
38
39
# File 'lib/skull_island/helpers/migration.rb', line 35

def migrate_1_1_to_1_4(config)
  new_config = config.dup
  new_config['version'] = '1.4'
  new_config
end

#migrate_config(config) ⇒ Object



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

def migrate_config(config)
  if config['version'] == '0.14'
    migrate_config migrate_0_14_to_1_1(config)
  elsif ['1.1', '1.2', '1.3'].include?(config['version'])
    migrate_1_1_to_1_4(config)
  else
    false # Just return false if it can't be migrated
  end
end