Commit 842b177c6b2b96b314f7126a1b73950482b4560b
1 parent
a937413c
Exists in
master
and in
1 other branch
add task to fix mismatch between prompt_ids
some appearances and their related votes did not have match prompt_ids. This task will update the appearance's prompt_id to match the vote's prompt_id.
Showing
1 changed file
with
18 additions
and
2 deletions
Show diff stats
lib/tasks/prune_db.rake
| ... | ... | @@ -2,7 +2,23 @@ namespace :prune_db do |
| 2 | 2 | |
| 3 | 3 | task :all => [:invalidate_votes_with_bad_response_times] |
| 4 | 4 | |
| 5 | - task(:invalidate_votes_with_bad_response_times => :environment) do | |
| 5 | + desc "Fixes a mis-match between a vote's prompt_id and its appearance's prompt_id. Sets the appearance prompt_id to match the vote's prompt_id" | |
| 6 | + task :fix_promptid_mismatch => :environment do | |
| 7 | + bad_records = Vote.connection.select_all " | |
| 8 | + SELECT | |
| 9 | + votes.prompt_id, appearances.id appearance_id, | |
| 10 | + appearances.prompt_id appearance_prompt_id | |
| 11 | + FROM votes LEFT JOIN appearances | |
| 12 | + ON (votes.id = appearances.answerable_id | |
| 13 | + AND appearances.answerable_type = 'Vote') | |
| 14 | + WHERE votes.prompt_id <> appearances.prompt_id" | |
| 15 | + bad_records.each do |record| | |
| 16 | + Appearance.update_all("prompt_id = #{record["prompt_id"]}", "id = #{record["appearance_id"]} AND prompt_id = #{record["appearance_prompt_id"]}") | |
| 17 | + end | |
| 18 | + end | |
| 19 | + | |
| 20 | + desc "Invalidates votes with bad response times" | |
| 21 | + task :invalidate_votes_with_bad_response_times => :environment do | |
| 6 | 22 | badvotes = [] |
| 7 | 23 | #might want to optimize later to not start from the beginning each time |
| 8 | 24 | STDOUT.sync = true |
| ... | ... | @@ -28,7 +44,7 @@ namespace :prune_db do |
| 28 | 44 | end |
| 29 | 45 | end |
| 30 | 46 | |
| 31 | - task(:associate_skips_with_appearances => :environment) do | |
| 47 | + task :associate_skips_with_appearances => :environment do | |
| 32 | 48 | skips_to_fix = Skip.find(:all, :conditions => {:appearance_id => nil}) |
| 33 | 49 | skips_to_fix.each do |skip| |
| 34 | 50 | puts "Skip #{skip.id} : " | ... | ... |