Last active
July 18, 2018 09:25
-
-
Save jozr/063ad517eaaf836f1cd5dd88b8a823b6 to your computer and use it in GitHub Desktop.
SALT-821: Migrate "ConversationElements::Feedback" to "ConversationElements::Plaintext"
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
@count = Conversation.where("conversation_groups.conversation_elements._type" => "ConversationElements::Feedback").count | |
Conversation.where("conversation_groups.conversation_elements._type" => "ConversationElements::Feedback").each_with_index do |conversation, i| | |
percentage = (i.to_f / @count) * 100 | |
puts "PROGRESS: #{percentage.to_s}" if percentage % 10 == 0 | |
for group in conversation.conversation_groups do | |
for element in group.conversation_elements do | |
if element._type == "ConversationElements::Feedback" | |
text = element.text | |
group.conversation_elements << ConversationElements::Plaintext.new(text: text) | |
element.delete | |
end | |
end | |
end | |
end |
there has to be a better way to do this...
apparently not after looking through MondoDB documentation
Yeah, there is no better way, unfortunately :)
If we would prepare this code to run in a continuous mode, I'd try to find a way to improve it (like iterators instead of for loops or remove a where condition, which will return 99.99% of all conversations anyway, but at the same time consumes some time to calculate), or even rewrite it to two more idiomatic mongo queries, but for our purpose it totally fine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For
there are 198 on staging and 2185 on production.