1 module MigrateYAMLToJSON
2 def self.migrate(table, column)
3 conn = ActiveRecord::Base.connection
5 "UPDATE #{table} SET #{column}=$1 WHERE #{column}=$2",
6 "#{table}.#{column} convert YAML to JSON",
7 [[nil, "{}"], [nil, "--- {}\n"]])
8 Rails.logger.info("#{table}.#{column}: #{n} rows updated using empty hash")
13 "SELECT id, #{column} FROM #{table} WHERE #{column} LIKE $1 LIMIT 100",
14 "#{table}.#{column} check for YAML",
16 ).rows.map do |id, yaml|
18 json = SafeJSON.dump(YAML.load(yaml))
20 "UPDATE #{table} SET #{column}=$1 WHERE id=$2 AND #{column}=$3",
21 "#{table}.#{column} convert YAML to JSON",
22 [[nil, json], [nil, id], [nil, yaml]])
24 Rails.logger.info("#{table}.#{column}: #{n} rows updated")