Merge branch '21666-provision-test-improvement'
[arvados.git] / services / api / lib / migrate_yaml_to_json.rb
index fbfc60362cd0bbf101bb5bfdee7892969321947e..8987f3364c245a04a988697c9c45510ef75bd9a8 100644 (file)
@@ -1,10 +1,14 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 module MigrateYAMLToJSON
   def self.migrate(table, column)
     conn = ActiveRecord::Base.connection
     n = conn.update(
       "UPDATE #{table} SET #{column}=$1 WHERE #{column}=$2",
       "#{table}.#{column} convert YAML to JSON",
-      [[nil, "{}"], [nil, "--- {}\n"]])
+      ["{}", "--- {}\n"])
     Rails.logger.info("#{table}.#{column}: #{n} rows updated using empty hash")
     finished = false
     while !finished
@@ -12,14 +16,14 @@ module MigrateYAMLToJSON
       conn.exec_query(
         "SELECT id, #{column} FROM #{table} WHERE #{column} LIKE $1 LIMIT 100",
         "#{table}.#{column} check for YAML",
-        [[nil, '---%']],
+        ['---%'],
       ).rows.map do |id, yaml|
         n += 1
-        json = SafeJSON.dump(YAML.load(yaml))
+        json = SafeJSON.dump(YAML.safe_load(yaml))
         conn.exec_query(
           "UPDATE #{table} SET #{column}=$1 WHERE id=$2 AND #{column}=$3",
           "#{table}.#{column} convert YAML to JSON",
-          [[nil, json], [nil, id], [nil, yaml]])
+          [json, id, yaml])
       end
       Rails.logger.info("#{table}.#{column}: #{n} rows updated")
       finished = (n == 0)