1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 module MigrateYAMLToJSON
6 def self.migrate(table, column)
7 conn = ActiveRecord::Base.connection
9 "UPDATE #{table} SET #{column}=$1 WHERE #{column}=$2",
10 "#{table}.#{column} convert YAML to JSON",
11 [[nil, "{}"], [nil, "--- {}\n"]])
12 Rails.logger.info("#{table}.#{column}: #{n} rows updated using empty hash")
17 "SELECT id, #{column} FROM #{table} WHERE #{column} LIKE $1 LIMIT 100",
18 "#{table}.#{column} check for YAML",
20 ).rows.map do |id, yaml|
22 json = SafeJSON.dump(YAML.load(yaml))
24 "UPDATE #{table} SET #{column}=$1 WHERE id=$2 AND #{column}=$3",
25 "#{table}.#{column} convert YAML to JSON",
26 [[nil, json], [nil, id], [nil, yaml]])
28 Rails.logger.info("#{table}.#{column}: #{n} rows updated")