Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 01:10:28 +01:00
DEV: add data migration to split out log fields
Dieser Commit ist enthalten in:
Ursprung
ae271ce647
Commit
aa928c319e
1 geänderte Dateien mit 70 neuen und 0 gelöschten Zeilen
70
db/migrate/20210806135416_split_custom_wizard_log_fields.rb
Normale Datei
70
db/migrate/20210806135416_split_custom_wizard_log_fields.rb
Normale Datei
|
@ -0,0 +1,70 @@
|
||||||
|
class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
reversible do |dir|
|
||||||
|
dir.up do
|
||||||
|
# separate wizard/action/user into their own keys
|
||||||
|
|
||||||
|
wizard_logs = PluginStoreRow.where("
|
||||||
|
plugin_name = 'custom_wizard_log'
|
||||||
|
")
|
||||||
|
|
||||||
|
if wizard_logs.exists?
|
||||||
|
wizard_logs.each do |row|
|
||||||
|
begin
|
||||||
|
log_json = JSON.parse(row.value)
|
||||||
|
rescue TypeError, JSON::ParserError
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
# first three keys are wizard/action/user
|
||||||
|
|
||||||
|
if log_json.key?('message')
|
||||||
|
attr_strs = log_json['message'].split('; ', 4)
|
||||||
|
|
||||||
|
log_json['message'] = attr_strs.pop
|
||||||
|
|
||||||
|
attr_strs.each do |attr_str|
|
||||||
|
key, value = attr_str.split(': ')
|
||||||
|
log_json[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
row.value = log_json.to_json
|
||||||
|
row.save
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
dir.down do
|
||||||
|
wizard_logs = PluginStoreRow.where("
|
||||||
|
plugin_name = 'custom_wizard_log'
|
||||||
|
")
|
||||||
|
|
||||||
|
if wizard_logs.exists?
|
||||||
|
wizard_logs.each do |row|
|
||||||
|
begin
|
||||||
|
log_json = JSON.parse(row.value)
|
||||||
|
rescue TypeError, JSON::ParserError
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
# concatenate wizard/action/user to start of message
|
||||||
|
prefixes = log_json.extract!('wizard', 'action', 'user')
|
||||||
|
|
||||||
|
message_prefix = prefixes.map{|k,v| "#{k}: #{v}"}.join('; ')
|
||||||
|
|
||||||
|
if log_json.key?('message')
|
||||||
|
log_json['message'] = "#{message_prefix}; #{log_json['message']}"
|
||||||
|
else
|
||||||
|
log_json['message'] = message_prefix
|
||||||
|
end
|
||||||
|
|
||||||
|
row.value = log_json.to_json
|
||||||
|
row.save
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Laden …
In neuem Issue referenzieren