journalduhacker/db/migrate/20150211170052_move_hidden_votes_to_hidden_story.rb
joshua stein f9b309d342 separate story hiding from voting
A story downvote is considered a flag, just meaning the story has
problems and not necessarily that the user wants to ignore it.  By
moving hiding out of Vote and into a new HiddenStory model, a user
can now both downvote/flag and hide separately, or just one or the
other.
2015-02-11 11:37:03 -06:00

20 lines
442 B
Ruby

class MoveHiddenVotesToHiddenStory < ActiveRecord::Migration
def up
create_table :hidden_stories do |t|
t.integer :user_id
t.integer :story_id
end
add_index "hidden_stories", ["user_id", "story_id"], :unique => true
Vote.where(:vote => 0).each do |v|
hs = HiddenStory.new
hs.user_id = v.user_id
hs.story_id = v.story_id
hs.save!
end
Vote.where(:vote => 0).delete_all
end
end