Updated

db/migrate / 20150924091057_set_debate_state_on_petitions.rb

A
37 lines of codes
2 methods
3.0 complexity/method
1 churn
6.0 complexity
0 duplications
class SetDebateStateOnPetitions < ActiveRecord::Migration
  1. SetDebateStateOnPetitions has no descriptive comment
def up execute <<-SQL UPDATE petitions SET debate_state = 'awaiting' WHERE debate_threshold_reached_at IS NOT NULL AND scheduled_debate_date IS NULL SQL execute <<-SQL UPDATE petitions SET debate_state = 'awaiting' WHERE scheduled_debate_date >= CURRENT_DATE SQL execute <<-SQL UPDATE petitions SET debate_state = 'debated' WHERE debate_outcome_at IS NOT NULL SQL execute <<-SQL UPDATE petitions SET debate_state = 'none' WHERE debate_outcome_at IS NOT NULL AND id IN (SELECT id FROM debate_outcomes WHERE debated = 'f') SQL execute <<-SQL UPDATE petitions SET debate_state = 'closed' WHERE state = 'closed' AND debate_threshold_reached_at IS NULL AND scheduled_debate_date IS NULL AND debate_outcome_at IS NULL SQL end def down
  1. SetDebateStateOnPetitions#down doesn't depend on instance state (maybe move it to another class?)
Petition.update_all(debate_state: 'pending') end end