Fixed migration erroring (#1681)

v2
Ahmad Farhat 3 years ago committed by GitHub
parent db6db06a78
commit b0de03cc09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      db/migrate/20200413150518_add_role_id_to_users.rb

@ -16,7 +16,7 @@ class AddRoleIdToUsers < ActiveRecord::Migration[5.2]
MigrationProduct.where(role_id: nil).each do |user|
highest_role = SubMigrationProduct.joins("INNER JOIN users_roles ON users_roles.role_id = roles.id")
.where("users_roles.user_id = '#{user.id}'").min_by(&:priority).id
.where("users_roles.user_id = '#{user.id}'")&.min_by(&:priority)&.id
user.update_attributes(role_id: highest_role) unless highest_role.nil?
end
end