Created
October 22, 2018 16:16
-
-
Save thescubageek/0f2aaf60506cf330b659b03097cf20e2 to your computer and use it in GitHub Desktop.
Bulk assign punch item assignments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project_id = 69 # replace with project id | |
login_ids = [332, 331, 133, 267, 119, 249, 251, 250] # replace with assignee login ids | |
batch_size = 300 # replace with batch size | |
pi_ids = PunchItem.where(project_id: project_id).where("deleted_at IS NULL").pluck(:id) | |
already_used_ids = PunchItemAssignment.where(punch_item_id: pi_ids).pluck(:punch_item_id) | |
pi_ids = (pi_ids - already_used_ids).shuffle | |
idx = 0 | |
PunchItem.includes(:punch_item_assignments).where(id: pi_ids).find_each(batch_size: batch_size) do |pi| | |
puts "Creating punch item assignment ##{idx+1}" | |
li = login_ids.sample | |
unless pi.punch_item_assignments.pluck(:login_information_id).include?(li) | |
pi.punch_item_assignments.create!( | |
login_information_id: li, | |
status: PunchItemAssignment::STATUSES.sample | |
) | |
end | |
idx += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment