Created
August 7, 2022 01:51
-
-
Save scytacki/3473bc303e36801391f5d54de07eeb1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def swap_image_question_prompts | |
mis_processed = 0 | |
managed_interactives = ManagedInteractive.where(library_interactive_id: 41).where("legacy_ref_id is not null").where("updated_at < '2022-08-04'") | |
mis_to_process = managed_interactives.count | |
managed_interactives.find_in_batches(batch_size: 1000) { |batch| | |
ActiveRecord::Base.transaction { | |
batch.each { |mi| | |
authored_state = JSON.parse(mi.authored_state) | |
prompt = authored_state["prompt"] | |
answerPrompt = authored_state["answerPrompt"] | |
authored_state["prompt"] = answerPrompt | |
authored_state["answerPrompt"] = prompt | |
mi.update_column(:authored_state, authored_state.to_json) | |
mis_processed += 1 | |
} | |
puts "#{mis_processed} of #{mis_to_process} processed." | |
} | |
} | |
puts "Processed #{mis_processed} of #{mis_to_process}." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment