[Fix #3196] Convert YAML to JSON
This commit is contained in:
parent
36d6a43084
commit
2a758d0759
2 changed files with 22 additions and 3 deletions
|
@ -39,11 +39,14 @@ class TypeDeChamp < ApplicationRecord
|
|||
|
||||
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles
|
||||
|
||||
# TODO start: remove after migrating `options` column to (non YAML encoded) JSON
|
||||
# TODO simplify after migrating `options` column to (non YAML encoded) JSON
|
||||
class MaybeYaml
|
||||
def load(options)
|
||||
if options.is_a?(String)
|
||||
case options
|
||||
when String
|
||||
YAML.safe_load(options, [ActiveSupport::HashWithIndifferentAccess])
|
||||
when Hash
|
||||
options.with_indifferent_access
|
||||
else
|
||||
options
|
||||
end
|
||||
|
@ -55,7 +58,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
|
||||
serialize :options, MaybeYaml.new
|
||||
# TODO stop: remove after migrating `options` column to (non YAML encoded) JSON
|
||||
|
||||
after_initialize :set_dynamic_type
|
||||
after_create :populate_stable_id
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: migrate_types_de_champ_options_to_json'
|
||||
task migrate_types_de_champ_options_to_json: :environment do
|
||||
puts "Running deploy task 'migrate_types_de_champ_options_to_json'"
|
||||
|
||||
dirty_tdcs = TypeDeChamp.where.not(options: nil)
|
||||
progress = ProgressReport.new(dirty_tdcs.count)
|
||||
dirty_tdcs.find_each do |tdc|
|
||||
tdc.options_will_change!
|
||||
tdc.save
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
|
||||
AfterParty::TaskRecord.create version: '20181219175043'
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue