From 35ff172967eaa4964e9e919688dc090dd7a29cce Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Tue, 24 Aug 2021 20:41:51 +0800 Subject: [PATCH] DEV: specify which fields to split in log data migration --- ...06135416_split_custom_wizard_log_fields.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb index b261c497..2e7b7d21 100644 --- a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb +++ b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb @@ -16,16 +16,23 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] next end - # first three keys are wizard/action/user - if log_json.key?('message') - attr_strs = log_json['message'].split('; ', 4) + if log_json.key?('message') and log_json['message'].is_a? String - log_json['message'] = attr_strs.pop + attr_strs = [] + + # assumes no whitespace in the values + attr_strs << log_json['message'].slice!(/(wizard: \S*; )/, 1) + attr_strs << log_json['message'].slice!(/(action: \S*; )/, 1) + attr_strs << log_json['message'].slice!(/(user: \S*; )/, 1) attr_strs.each do |attr_str| - key, value = attr_str.split(': ') - log_json[key] = value + if attr_str.is_a? String + attr_str.gsub!(/[;]/ ,"") + key, value = attr_str.split(': ') + value.strip! if value + log_json[key] = value ? value : '' + end end row.value = log_json.to_json