Skip to content

Commit

Permalink
AP-5141: Add a rake task to migrate types from old to new
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbruce committed Jul 10, 2024
1 parent 98ff000 commit 9b86f4b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/tasks/migrate_partner_attachments.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace :migrate do
desc "AP-5141 migrate attachment names after length exceeded CCMS limits"

task partner_attachments: :environment do
changes = {
partner_bank_statement_evidence: "part_bank_state_evidence",
partner_bank_statement_evidence_pdf: "part_bank_state_evidence_pdf",
partner_employment_evidence: "part_employ_evidence",
partner_employment_evidence_pdf: "part_employ_evidence_pdf",
}

attachments = Attachment.where(attachment_type: changes.keys)
documents = CCMS::SubmissionDocument.where(document_type: changes.keys)
Rails.logger.info "Migrating filenames"
Rails.logger.info "----------------------------------------"
Rails.logger.info "Affected attachments : #{attachments.count}"
Rails.logger.info "Affected documents : #{documents.count}"
Rails.logger.info "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
Benchmark.benchmark do |bm|
bm.report("Migrate:") do
ActiveRecord::Base.transaction do
attachments.each do |file|
file.attachment_type = changes[file.attachment_type.to_sym]
file.save!(touch: false) # this prevents the updated_at date being changed and delaying purging of stale records
end
raise StandardError, "Not all attachments updated" if Attachment.where(attachment_type: changes.keys).count.positive?

documents.each do |file|
file.document_type = changes[file.document_type.to_sym]
file.save!(touch: false) # this prevents the updated_at date being changed and delaying purging of stale records
end
raise StandardError, "Not all documents updated" if CCMS::SubmissionDocument.where(document_type: changes.keys).count.positive?
end
end
end
Rails.logger.info "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
Rails.logger.info "Attachments updated : #{Attachment.where(attachment_type: changes.values).count}"
Rails.logger.info "Documents updated : #{CCMS::SubmissionDocument.where(document_type: changes.values).count}"
Rails.logger.info "Attachments not updated: #{Attachment.where(attachment_type: changes.keys).count}"
Rails.logger.info "Documents not updated : #{CCMS::SubmissionDocument.where(document_type: changes.keys).count}"
Rails.logger.info "----------------------------------------"
end
end

0 comments on commit 9b86f4b

Please sign in to comment.