增加数据迁移文件

This commit is contained in:
sw 2014-06-18 11:51:20 +08:00
parent efb6c1fd19
commit 8f78177d47
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,25 @@
class RemoveDataToHomeworkAttach < ActiveRecord::Migration
def up
bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3")
bidding_projects.each do |biding|
homework = HomeworkAttach.new
homework.project_id = biding.project_id
homework.bid_id = biding.bid_id
homework.created_at = biding.created_at
homework.updated_at = biding.updated_at
homework.reward = biding.reward
homework.description = biding.description
homework.user_id = biding.user_id
homework.state = 0
homework.save
end
end
def down
bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3")
bidding_projects.each do |biding|
homework = HomeworkAttach.where("bid_id = #{biding.bid_id} and user_id = #{biding.user_id}")
homework.first.destroy
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140617092219) do
ActiveRecord::Schema.define(:version => 20140618020535) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false