20300: Update exec_query bind vars usage for Rails 7.
authorTom Clegg <tom@curii.com>
Thu, 21 Sep 2023 18:56:21 +0000 (14:56 -0400)
committerTom Clegg <tom@curii.com>
Fri, 29 Sep 2023 14:14:14 +0000 (10:14 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/app/models/group.rb
services/api/app/models/node.rb
services/api/app/models/user.rb
services/api/db/migrate/20180917205609_recompute_file_names_index.rb
services/api/db/migrate/20220726034131_write_via_all_users.rb
services/api/lib/can_be_an_owner.rb
services/api/lib/migrate_yaml_to_json.rb
services/api/lib/update_permissions.rb
services/api/lib/update_priorities.rb

index 5c0aeba589aa65867bd30c48dd56fd9a8fce3193..b6970459b6514db02b2c251561ed61d84ca83aae 100644 (file)
@@ -168,9 +168,9 @@ class Group < ArvadosModel
       "create temporary table #{temptable} on commit drop " +
       "as select * from project_subtree_with_trash_at($1, LEAST($2, $3)::timestamp)",
       "Group.update_trash.select",
-      [[nil, self.uuid],
-       [nil, TrashedGroup.find_by_group_uuid(self.owner_uuid).andand.trash_at],
-       [nil, self.trash_at]])
+      [self.uuid,
+       TrashedGroup.find_by_group_uuid(self.owner_uuid).andand.trash_at,
+       self.trash_at])
     frozen_descendants = ActiveRecord::Base.connection.exec_query(
       "select uuid from frozen_groups, #{temptable} where uuid = target_uuid",
       "Group.update_trash.check_frozen")
@@ -200,16 +200,16 @@ class Group < ArvadosModel
     ActiveRecord::Base.connection.exec_query(
       "create temporary table #{temptable} on commit drop as select * from project_subtree_with_is_frozen($1,$2)",
       "Group.update_frozen.select",
-      [[nil, self.uuid],
-       [nil, !self.frozen_by_uuid.nil?]])
+      [self.uuid,
+       !self.frozen_by_uuid.nil?])
     if frozen_by_uuid
       rows = ActiveRecord::Base.connection.exec_query(
         "select cr.uuid, cr.state from container_requests cr, #{temptable} frozen " +
         "where cr.owner_uuid = frozen.uuid and frozen.is_frozen " +
         "and cr.state not in ($1, $2) limit 1",
         "Group.update_frozen.check_container_requests",
-        [[nil, ContainerRequest::Uncommitted],
-         [nil, ContainerRequest::Final]])
+        [ContainerRequest::Uncommitted,
+         ContainerRequest::Final])
       if rows.any?
         raise ArgumentError.new("cannot freeze project containing container request #{rows.first['uuid']} with state = #{rows.first['state']}")
       end
@@ -240,11 +240,11 @@ class Group < ArvadosModel
     ActiveRecord::Base.connection.exec_delete(
       "delete from trashed_groups where group_uuid=$1",
       "Group.clear_permissions_trash_frozen",
-      [[nil, self.uuid]])
+      [self.uuid])
     ActiveRecord::Base.connection.exec_delete(
       "delete from frozen_groups where uuid=$1",
       "Group.clear_permissions_trash_frozen",
-      [[nil, self.uuid]])
+      [self.uuid])
   end
 
   def assign_name
index 9e250acfb11f794e78452ab5e08746ad8c973eec..3f0e0b56166fa1718b11f3dc7a2ee2b9df09cf74 100644 (file)
@@ -163,8 +163,8 @@ class Node < ArvadosModel
                           LIMIT 1',
                           # query label:
                           'Node.available_slot_number',
-                          # [col_id, val] for $1 vars:
-                          [[nil, MAX_VMS]],
+                          # bind vars:
+                          [MAX_VMS],
                          ).rows.first.andand.first
   end
 
index afc2d18b8a306efc29ebecb88ce7a1e888c536f0..37603a86e3dcd37b55fc15c1c34c88d9b8517775 100644 (file)
@@ -145,10 +145,10 @@ SELECT 1 FROM #{PERMISSION_VIEW}
 },
                   # "name" arg is a query label that appears in logs:
                    "user_can_query",
-                   [[nil, self.uuid],
-                    [nil, target_uuid],
-                    [nil, VAL_FOR_PERM[action]],
-                    [nil, target_owner_uuid]]
+                   [self.uuid,
+                    target_uuid,
+                    VAL_FOR_PERM[action],
+                    target_owner_uuid]
                   ).any?
         return false
       end
@@ -237,7 +237,7 @@ SELECT target_uuid, perm_level
                    # "name" arg is a query label that appears in logs:
                    "User.group_permissions",
                    # "binds" arg is an array of [col_id, value] for '$1' vars:
-                   [[nil, uuid]]).
+                   [uuid]).
         rows.each do |group_uuid, max_p_val|
         @group_perms[group_uuid] = PERMS_FOR_VAL[max_p_val.to_i]
       end
index b321422143b9e7df21ed6c7cfb55a3193ba6ca80..ed6be3bfe1cd0f208a055cce603528341190b586 100644 (file)
@@ -8,7 +8,7 @@ class RecomputeFileNamesIndex < ActiveRecord::Migration[4.2]
     Collection.select(:portable_data_hash, :manifest_text).where(portable_data_hash: pdhs).distinct(:portable_data_hash).each do |c|
       ActiveRecord::Base.connection.exec_query("update collections set file_names=$1 where portable_data_hash=$2",
                                                "update file_names index",
-                                               [[nil, c.manifest_files], [nil, c.portable_data_hash]])
+                                               [c.manifest_files, c.portable_data_hash])
     end
     ActiveRecord::Base.connection.exec_query('COMMIT')
   end
index 30e6463beb62c795485cded973c52501b14ee0ce..f1280597f9db71cc9504a065c923347bec173b7a 100644 (file)
@@ -14,11 +14,11 @@ class WriteViaAllUsers < ActiveRecord::Migration[5.2]
     ActiveRecord::Base.connection.exec_query(
       "update links set name=$1 where link_class=$2 and name=$3 and tail_uuid like $4 and head_uuid = $5",
       "migrate", [
-        [nil, to],
-        [nil, "permission"],
-        [nil, from],
-        [nil, "_____-tpzed-_______________"],
-        [nil, all_users_group_uuid],
+        to,
+        "permission",
+        from,
+        "_____-tpzed-_______________",
+        all_users_group_uuid,
       ])
   end
 end
index fc66f84bfc7e4cf52df8ea9f64595a4e6d9ed40f..e09037819c64fff413df491ce9e74e6d5febfaef 100644 (file)
@@ -62,7 +62,7 @@ module CanBeAnOwner
                   # "name" arg is a query label that appears in logs:
                   "descendant_project_uuids for #{self.uuid}",
                   # "binds" arg is an array of [col_id, value] for '$1' vars:
-                  [[nil, self.uuid], [nil, 'project']],
+                  [self.uuid, 'project'],
                   ).rows.map do |project_uuid,|
       project_uuid
     end
index aa2af60b25552187776ef4c797598d0990990b32..8987f3364c245a04a988697c9c45510ef75bd9a8 100644 (file)
@@ -8,7 +8,7 @@ module MigrateYAMLToJSON
     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
@@ -16,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.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)
index b7e5476404869f6a89603302eafe828397acd1c5..799bc40ba2c05f896f7d871ed96cdf3539acd2c0 100644 (file)
@@ -111,10 +111,10 @@ create temporary table #{temptable_perms} on commit drop
 as select * from compute_permission_subgraph($1, $2, $3, $4)
 },
                                              'update_permissions.select',
-                                             [[nil, perm_origin_uuid],
-                                              [nil, starting_uuid],
-                                              [nil, perm_level],
-                                              [nil, edge_id]]
+                                             [perm_origin_uuid,
+                                              starting_uuid,
+                                              perm_level,
+                                              edge_id]
 
     ActiveRecord::Base.connection.exec_query "SET LOCAL enable_mergejoin to true;"
 
index 4183ac10b15bed9436022618b7f563c53e9938c0..94115340df3c7fb807acfba0c90ff49d95020107 100644 (file)
@@ -17,7 +17,7 @@ UNION
           and container_requests.requesting_container_uuid is not NULL
 )
         order by containers.uuid for update
-  }, 'select_for_update_priorities', [[nil, container_uuid]]
+  }, 'select_for_update_priorities', [container_uuid]
 end
 
 def update_priorities starting_container_uuid
@@ -27,5 +27,5 @@ def update_priorities starting_container_uuid
   ActiveRecord::Base.connection.exec_query %{
 update containers set priority=computed.upd_priority from container_tree_priorities($1) as computed
  where containers.uuid = computed.pri_container_uuid and priority != computed.upd_priority
-}, 'update_priorities', [[nil, starting_container_uuid]]
+}, 'update_priorities', [starting_container_uuid]
 end